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

19th Feb 2020, 4:40 PM
Mush
Mush - avatar
1 Answer
+ 1
v1.color = “red” assigns red to property color of Vehicle v1. To print it use System.out.println(v1.color)
19th Feb 2020, 4:53 PM
Gabriel Ilie
Gabriel Ilie - avatar