че делать то надо?
package com.javarush.task.task21.task2108;
import java.util.Arrays;
/*
Клонирование растений
*/
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) 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;
}
@Override
protected Object clone() throws CloneNotSupportedException {
Tree cloneTree = (Tree)super.clone();
return cloneTree;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Tree tree = (Tree) o;
return Arrays.equals(branches, tree.branches);
}
@Override
public int hashCode() {
return Arrays.hashCode(branches);
}
public String[] getBranches() {
return branches;
}
}
}