zoukankan      html  css  js  c++  java
  • protected和default

    // a包
    public class Student{
        public void eat(){
            System.out.println("吃饭");
            super.action();
        }
        private void exam(){
            System.out.println("学生在考试");
        }
        protected void cadre(){
            System.out.println("竞选干部");
        }
        void study(){
            System.out.println("学习");
        }
    }
    
    // b包
    public class XiaoMing extends Student {
        public XiaoMing() {
            super.cadre();
            super.action();
            // 不同包调用protected只能在子孙类中
            new 基类的子孙类().protected方法();
        }
    }
    // b包
    public class MyClass {
        public static void main(String[] args) {
            new XiaoMing().cadre(); // 因为MyClass类和People类不同包所以xiaoMing的实例不可以调用protected方法
        }
    }

    protected、default同包下和public并无区别,default只能在同包下访问

    你的努力有资格到拼天赋的程度吗?
  • 相关阅读:
    团购网站之大众点评
    cas xml
    smsUtil
    solr配置
    xml
    yu
    Schema.xml
    ApplicationContext-redis.xml
    fast
    第一版
  • 原文地址:https://www.cnblogs.com/wchjdnh/p/14418459.html
Copyright © 2011-2022 走看看