+ 1
Hi, how can i write system.out.println( color for v1and v3 is red) actually for more than two vehicles
public class Vehicle { private String color; Vehicle() { this.setColor("Red"); } Vehicle(String c) { this.setColor(c); } public void setColor(String c) { this.color = c; } public String getColor() { return color; Vehicle v1 = new Vehicle(); Vehicle v3= new Vehicle(); Vehicle v2 = new Vehicle("Green"); System.out.println(v2.getColor);
4 Réponses
+ 1
i want the output for this code be: v1 and v3 are red and v2 is green with one
system.out.println(????);
+ 1
thank you
0
Can you explain a little bit more what you want?
0
You can use "+" to connect several strings.
System.out.println("V1 and V3 are " + v1.getColor() + " V2 is " + v2.getColor());
If you want a code that finds which one are equal, it will take a little bit more of work, but it's not hard.