本包 非本包 非本包的子类 本类
public 公共的 y y y y
protected 受保护的 y X y y
default 默认缺省/ 友元 y X X y
private 私有 X X X y
package com. znsd. two;
public class Main {
public static void main ( String[ ] args) {
Test t= new Test ( ) ;
t. method ( ) ;
t. methodTwo ( ) ;
t. fun ( ) ;
t. funTwo ( ) ;
}
}
package com. znsd. two;
public class Test {
public static void method ( ) {
System. out. println ( "公共的静态方法" ) ;
}
protected static void methodTwo ( ) {
System. out. println ( "受保护的静态方法" ) ;
}
static void methodThree ( ) {
System. out. println ( "默认的静态方法" ) ;
}
private static void methodFour ( ) {
System. out. println ( "私有的静态方法" ) ;
}
public void fun ( ) {
System. out. println ( "公共的非静态方法" ) ;
}
protected void funTwo ( ) {
System. out. println ( "受保护的非静态方法" ) ;
}
void funTree ( ) {
System. out. println ( "默认的非静态方法" ) ;
}
private void funFour ( ) {
System. out. println ( "私有的非静态方法" ) ;
}
}
class TestTwo {
protected class Inter {
}
}
package com. znsd. one;
import com. znsd. two. Test;
public class Main {
public static void main ( String[ ] args) {
Test t= new Test ( ) ;
t. method ( ) ;
t. fun ( ) ;
}
}
package com. znsd. one;
import com. znsd. two. Test;
public class MainTwo extends Test {
public static void main ( String[ ] args) {
MainTwo main= new MainTwo ( ) ;
main. method ( ) ;
main. methodTwo ( ) ;
main. fun ( ) ;
main. funTwo ( ) ;
}
}