class Parent implements Cloneable{
int i ;
Parent(){
}
Parent(int i){
this.i = i;
}
public Object clonemyobj() throws CloneNotSupportedException{
return this.clone();
}
protected Object cloneme() throws CloneNotSupportedException {
return this.clone();
}
}
class Child extends Parent{
}
public class CloneDemo{
public static void main(String... ar) throws CloneNotSupportedException
{
Parent p = new Parent(10);
Object o1 = p.cloneme();
// 1. cloneme() is a protected method in parent class i am able to access it
//Object o2 = p.clone();
// 2. the above line shows clone() has protected access in java.lang.object
// but that should be the same with cloneme() method in parent class
// why?
Object o = new Object();
Child c = new Child();
//3. o.clone();
c.cloneme();
//4.(c.cloneme()) is a protected method in parent class
// but still able to access it using child class object
}
}
All my above classes are in same package.
- can anyone provide me with explanation for all the above four bullet points?
- How would each of these would execute?