• 5、Java 修饰符


    Java访访

    1访

    publicprotecteddefaultprivate西使

    2

      protected使javajavamainmain

      main使访main访java访访

      访privatepublic

    3

    package com.example.test;

    /**
    * @author lin
    * @version 1.0
    * @date 2020/6/21 20:21
    * @Description TODO
    */
    public class Person {
       public String uname = "person  ";

       public void introduceMyself() {
           System.out.println("com.example.test " + uname);
      }
    }
    package com.example.test;

    /**
    * @author lin
    * @version 1.0
    * @date 2020/6/21 20:21
    * @Description TODO
    */
    public class Student {
       Person p = new Person();

       public void test() {
           System.out.println("com.example.test " + p.uname);
      }
    }
    package com.example.test;

    /**
    * @author lin
    * @version 1.0
    * @date 2020/6/21 20:21
    * @Description TODO
    */
    public class Teacher extends Person {
       public int age;
       Person p = new Person();

       public void test1() {
           System.out.println("com.example.test " + p.uname);
      }
    }
    package com.example.test2;

    /**
    * @author lin
    * @version 1.0
    * @date 2020/6/21 20:22
    * @Description TODO
    */
    public class Person {
       public String uname = "haha";

       public void test2() {
           System.out.println("com.example.test2 " + uname);
      }

    }

    package com.example.test;

    /**
    * @author lin
    * @version 1.0
    * @date 2020/6/21 20:23
    * @Description TODO
    */
    public class Test {
       public static void main(String[] args) {
           Person person = new Person();
           person.introduceMyself();
           Student student = new Student();
           student.test();
           Teacher teacher = new Teacher();
           teacher.test1();
           com.example.test2.Person person1 = new com.example.test2.Person();
           person1.test2();
      }
    }

    1 public访

    2  protected

    Personuanmeprotected  Parents便  The field Person.uname is not visible

    3private

    访 Personunamesetget便访

    4default

    访  使 访

  • 相关阅读:
    工作中的几个问题
    linux初学之二
    VMWARE虚拟机卡死
    记昨天、今天的部分工作内容及问题
    linux初学之一
    今日阅读项目源码
    python POST XML
    python的超简单WEB服务器
    在notepad++中运行python
    安装python图形库:Matplotlib
  • 原文地址:https://www.cnblogs.com/naimao/p/13346482.html
Copyright © 2020-2023  润新知