4.67 4種類の権限修飾子のテスト
1677 ワード
/*
:
( ) ( ) ( )
private Y
Y Y
protected Y Y Y
public Y Y Y Y
*/
package com.test;
public class Father {
private void show() {
System.out.println("show");
}
void show2() {
System.out.println("show2");
}
protected void show3() {
System.out.println("show3");
}
public void show4() {
System.out.println("show4");
}
public static void main(String[] args) {
Father f = new Father();
f.show();
f.show2();
f.show3();
f.show4();
}
}
package com.test;
class Son extends Father {
public static void main(String[] args) {
Father f = new Father();
// f.show();
f.show2();
f.show3();
f.show4();
System.out.println("--------------");
Son s = new Son();
// s.show();
s.show2();
s.show3();
s.show4();
}
}
package com.test;
public class Test {
public static void main(String[] args) {
Father f = new Father();
// f.show();
f.show2();
f.show3();
f.show4();
}
}
package cn.test;
import com.test.Father;
public class Son2 extends Father {
public static void main(String[] args) {
Father f = new Father();
// f.show();
// f.show2();
// f.show3();
f.show4();
System.out.println("--------------");
Son2 s = new Son2();
// s.show();
// s.show2();
s.show3();
s.show4();
}
}
package cn.test;
import com.test.Father;
public class Test2 {
public static void main(String[] args) {
Father f = new Father();
// f.show();
// f.show2();
// f.show3();
f.show4();
}
}