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
}
}
위의 모든 클래스는 동일한 패키지에 있습니다.보호 액세스 수정자는 작동하며 Object 클래스 복제 방법에 액세스하는 것과 어떻게 다른가요
- 위의 네 가지 글 머리 기호 모두에 대해 설명해 줄 수있는 사람이 있습니까?
- 이들 각각은 어떻게 실행됩니까?
[편집] 질문에 올바른 코드와 텍스트 서식을 지정하십시오. – user1803551
코드와 텍스트 포맷을 수정했습니다 –
왜이 코드를 실행하고 * 각각의 실행 방법은 무엇입니까? * – NewUser