Home

韧桂

思考,总结

四种权限修饰符

代码一

package eight;

public class Order {
    private String orderName;
    int orderId;
    protected int orderNum;
    public String orderDesc;

    private void method1(){
        orderName = "AA";
    }
    void method2(){

    }
    protected void method3(){

    }
    public void method4(){

    }
}

代码二

package eight;

public class OrderA {
    public static void main(String[] args) {
        Order o = new Order();
        o.orderDesc = null;
        o.orderId = 1;
        o.orderNum = 1001;
    }
}

代码三:在另一个包下

package eightdemo;
import eight.Order;

public class OrderB {
    public static void main(String[] args) {
        Order o = new Order();
        o.orderDesc = null;
    }
}

class Order1 extends Order{
    public void method5(){
        orderNum = 1002;
        method3();
//        method2();//调不了
    }
}

韧桂 2019-12-25