0
Can anyone explain v1.color = "red"; line?Also how do I print it?
public class Vehicle { int maxSpeed; int wheels; String color; double fuelCapacity; void horn() { System.out.println("Beep!"); } } class MyClass { public static void main(String[ ] args) { Vehicle v1 = new Vehicle(); Vehicle v2 = new Vehicle(); v1.color = "red"; v2.horn(); } }
1 Answer
+ 1
v1.color = âredâ assigns red to property color of Vehicle v1.
To print it use System.out.println(v1.color)