+ 1

Getter & Setter Problem in Java Code!!

I tried several time without using google but still I failed to get the correct output. If anyone here know about this edit my code and adding comments of the fixes. I shall be very thankful to you for this. https://code.sololearn.com/c2VYvgIlsj15/?ref=app https://code.sololearn.com/cDiQdHFN31KV/?ref=app

23rd Jul 2018, 5:56 PM
Robin
Robin - avatar
5 ответов
+ 2
Instead of writing the fields as the type and object write the class name e.g. Car myCar = new Car(); When using doubles put d after the number because by default theyre floats e.g. 3.14d Fields that have getters and setters should be private and to access their value use the getter method instead of trying to get the field directly
23rd Jul 2018, 6:05 PM
TurtleShell
TurtleShell - avatar
+ 1
There are no problems with the getters and setters. The problem is, that you try to create an object of a variable, instead of the class.
23rd Jul 2018, 6:05 PM
Moritz Vogel
Moritz Vogel - avatar
+ 1
I still can't fix it can you please fix it I will get taught by this if you fix this for me.
23rd Jul 2018, 6:14 PM
Robin
Robin - avatar
+ 1
In the first example, you have to use System.out.println(obj.getSpeed());
23rd Jul 2018, 6:16 PM
Moritz Vogel
Moritz Vogel - avatar
0
You tried to print the object instead of calling the getter
23rd Jul 2018, 6:17 PM
Moritz Vogel
Moritz Vogel - avatar