Задачу не пропускает. Почему?
И я скопировала массив getBranches().clone, это значит что создался новый массив в памяти с другой ссылкой? Если так, то в нем ссылки на строки как и в первом массиве, или новые?
package com.javarush.task.task21.task2108;
/*
Клонирование растений
*/
public class Solution {
public static void main(String[] args) {
Tree tree = new Tree("willow", new String[]{"s1", "s2", "s3", "s4"});
Tree clone = null;
try {
clone = tree.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
System.out.println(tree);
System.out.println(clone);
System.out.println(tree.branches);
System.out.println(clone.branches);
}
public static class Plant {
private String name;
public Plant(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
public static class Tree extends Plant implements Cloneable{
private String[] branches;
public Tree(String name, String[] branches) {
super(name);
this.branches = branches;
}
public String[] getBranches() {
return branches;
}
@Override
protected Tree clone(){
Tree tree = new Tree(new String(getName()), getBranches().clone()) ;
return tree;
}
}
}