Код: Выделить всё
public class Car {
private String model;
private int year;
public Car(String model, int year) {
this.model = model;
this.year = year;
}
public void setModel(String model) {
this.model = model; // Allows modification of the model
}
public void setYear(int year) {
this.year = year; // Allows modification of the year
}
public void display() {
System.out.println("Model: " + model + ", Year: " + year);
}
public static void main(String[] args) {
Car car = new Car("Toyota", 2020);
car.display();
car.setModel("Honda"); // Modifying the model
car.setYear(2021); // Modifying the year
car.display();
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... ed-in-java