JAVA
java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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");
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run