- 1
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(); System.out.println(v1); } } Explain its outcome. I am unable to get the last line of outcome.
2 Respostas
+ 3
v1 is not a thing that you can "outcome" it. v1 is just. an object of a HOLE class. I mean, it's not a String or Int ect... maybe try specifying what you want to get from that class. so instead of saying (System.out.println(v1)) write (System.out.println(v1.color))
0
the last line actually only prints the hashcode for that vehicle object, as a toString() method was not defined in the vehicle class