0
What can i do to have a output in my program?
2 ответов
+ 3
Use System.out print() and also you need to make getter and setter method.
Do like this
public class vehicule {
private String color;
vehicule (String newColor) {
color = newColor ;
}
public String getColor() {
return color;
}
}
public class Program
{
public static void main(String[] args) {
vehicule v = new vehicule ("Vert");
System.out.print(v.getColor());
}
}
+ 1
as your class attribut 'color' is private, you should first create a getter method for it (in the class body).
public getColor(){
return this.color;
}
and then print vehicule.getColor() (in the main function)
System.out.println(vehicule.getColor())