+ 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()); } }

9th Nov 2016, 4:24 PM
ehsan shahbazi
ehsan shahbazi - avatar
3 Réponses
+ 3
thank you
9th Nov 2016, 4:48 PM
ehsan shahbazi
ehsan shahbazi - avatar
+ 1
Change this line : System.out.println(car.setColor()); to System.out.println(car.getColor()+"");
9th Nov 2016, 4:31 PM
Rahul Chittimalla
Rahul Chittimalla - avatar
+ 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.
9th Nov 2016, 4:37 PM
Lynda May
Lynda May - avatar