0

Where did I go wrong?

Note: I don't want to use getter setter or contractor.. https://code.sololearn.com/ccAZNnX5yME5/?ref=app

16th Jan 2021, 3:06 PM
Name
Name - avatar
1 Antwort
+ 4
public class Program { public static void main(String[] args) { Greetings y = new Greetings(); y.set(6); System.out.println(y.x); } } public class Greetings { int x; public void set(int num){ x = num; } } Two minor mistake committed by you in this code are, 1) You don't need a return type in a setter because you are getting nothing but only setting a value to a variable. [line 11] 2) You already made an object y of class Greetings, so try to use object "y" to access the property and not the class name itself. [line 6]
16th Jan 2021, 3:08 PM
RKK
RKK - avatar