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