+ 1
What is problem?
class Vehicle { private String color; public String getColor() { return color; } public void setColor(String c) { this.color = c; } } public class Program { public static void main(String[] args) { Vehicle car = new Vehicle(); car.setColor("red"); System.out.println(car.setColor()); } }
3 Réponses
+ 3
thank you
+ 1
Change this line :
System.out.println(car.setColor());
to
System.out.println(car.getColor()+"");
+ 1
Hi,
you cannot print out setColor() since it doesn't have a return value, it only changes the color (and it needs an argument). If you want to print out the cars color, you need to use the getColor() method.