#java #javatutorial #javacourse
public class Main {
public static void main(String[] args) {
Car[] cars = {new Car("Mustang", "Red"),
new Car("Corvette", "Blue"),
new Car("Charger", "Yellow")};
for(Car car : cars){
car.color = "black";
}
for(Car car : cars){
car.drive();
}
}
}
public class Car {
String model;
String color;
Car(String model, String color){
this.model = model;
this.color = color;
}
void drive(){
System.out.println("You drive the " + this.color + " " + this.model);
}
}
public class Main {
public static void main(String[] args) {
Car[] cars = {new Car("Mustang", "Red"),
new Car("Corvette", "Blue"),
new Car("Charger", "Yellow")};
for(Car car : cars){
car.color = "black";
}
for(Car car : cars){
car.drive();
}
}
}
public class Car {
String model;
String color;
Car(String model, String color){
this.model = model;
this.color = color;
}
void drive(){
System.out.println("You drive the " + this.color + " " + this.model);
}
}
- Category
- Bro Code
- Tags
- java tutorial, java course, java programming

Be the first to comment