Назад к задачамПолучайте помощь с лайвкодингом в реальном времени с Sobes Copilot
Junior — Senior
23
Получение копии экземпляра класса Bird
Условие задачи
Необходимо создать дубликат объекта класса Bird и разместить его в переменной birdClone.
public class JetbulbInterview {
public static void main(String[] args) {
Bird bird1 = new Bird("Buddy", 100);
System.out.println(bird1);
Bird birdClone = ...; // Создать клон объекта
System.out.println(birdClone);
}
}
class Bird {
private String name;
private int health;
public Bird(String name, int health) {
this.name = name;
this.health = health;
}
@Override
public String toString() {
return "Bird{name='" + name + "', health=" + health + "}";
}
}