I can't solve this... I keep getting " tree.clone can't be overridden"
package com.codegym.task.task21.task2108;
/*
Cloning plants
*/
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;
}
public boolean equals(Object o){
if(o == this)return true;
if(!(o instanceof Tree))return false;
Tree tree = (Tree)o;
return Objects.equals(tree.name, name)&& Objects.equals(tree.branches, branches);
}
public int hashCode (){
return Objects.hash(name, branches);
}
public Object clone() throws CloneNotSupportedException{
Tree tree = (Tree)super.clone();
return tree;
}
@Override
protected Object clone() throws CloneNotSupportedException {
Tree t = (Tree) super.clone();
t.branches = branches.clone();
return t;
}
}
}