setters and getters issue | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

setters and getters issue

Why is this bringing a runtime error? public class Vehicle { private String color; private int age; //getter for age public int getAge(){ return age; } //setter public void setAge(int age){ this.age = age; } // Getter public String getColor() { return color; } // Setter public void setColor(String c){ this.color = c; } } class Program { public static void main(String[ ] args) { Vehicle v1 = new Vehicle(); v1.setColor("green"); System.out.println(v1.getColor()); Vehicle ae = new Vehicle(); ae.setAge (12); System.out.println("the age is " +ae.getAge); } }

28th May 2020, 1:37 PM
@smike_designer!!🤓
@smike_designer!!🤓 - avatar
2 Answers
0
@smike_designer!!🤓 oh i just saw that, in your case you actually are not calling the function, you have forgetten the paranthesis, it should be ae.getAge() and not ae.getAge
28th May 2020, 1:48 PM
Mustafa K.
Mustafa K. - avatar
0
//System.out.println("the age is " +ae.getAge); // () System.out.println("the age is " +ae.getAge() );
28th May 2020, 6:58 PM
zemiak