public class Example implements Cloneable{
int x;
Example(int a){
this.x=a;
}
public String toString(){
return ""+x;
}
public Object clone() throws Exception{
return super.clone();
}
}
public class Test{
public static void main(String[] args) throws Exception{
Example obj=new Example(0);
Example obj2=(Example)obj.clone();
obj2.x=1;
System.out.println(obj);
System.out.println(obj2);
}
}
This program generates compile time error because it is not possible to increase the scope of the exception in the overriding methods.
Why is this so?