+ 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
5 Respostas
+ 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
+ 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.
+ 1
I still can't fix it can you please fix it I will get taught by this if you fix this for me.
+ 1
In the first example, you have to use System.out.println(obj.getSpeed());
0
You tried to print the object instead of calling the getter