Computer Science, asked by akash434, 1 year ago

public class Vehicle {
private String color;

Vehicle() {
this.setColor("Red");
}
Vehicle(String c) {
this.setColor(c);
}

// Setter
public void setColor(String c) {
this.color = c;
}

// Getter
public String getColor() {
return color;
}
}

public class Program {
public static void main(String[] args) {
//color will be "Red"
Vehicle v1 = new Vehicle();

//color will be "Green"
Vehicle v2 = new Vehicle("Green");

System.out.println(v2.getColor());
}
}

o/p : Green

can anyone explain this program pls?


Pranjal01: It's java ,right?

Answers

Answered by Arunvarma1
0
something not clear to answer

Pranjal01: U know java or not??
akash434: i am learning and i saw this program in sololearn app.. and i am confused with this.
Pranjal01: K,I've studied java for 2 yrs but I have no idea how this colour thing works. Never been taught about it.
akash434: kk . anyway thanks for answering
Similar questions