java中类的权限

来源:互联网 发布:java调用python程序 编辑:程序博客网 时间:2024/06/02 01:45

这里写图片描述

下面是模拟在一个类中,和在一个包中

package test.big1601;public class Student{    private void fei()    {        System.out.println("飞");    }    void pao()    {        System.out.println("跑");    }    protected void tiao()    {        System.out.println("跳");    }    public void pa()    {        System.out.println("爬");    }    public static void main(String[] args)     {        Student stu = new Student();        stu.fei();        stu.pao();        stu.tiao();        stu.pa();}class Demo4 {    public static void main(String[] args)     {        Student stu = new Student();        //stu.fei();        stu.pao();        stu.tiao();        stu.pa();    }}
import test.big1601.Student;class Demo5 //extends Student{    public static void main(String[] args)     {        //Demo5 d = new Demo5();//子类可以访问父类中的protected和public权限的        //d.fei();        //d.pao();        //d.tiao();        //d.pa();        Student stu = new Student();        //stu.fei();        //stu.pao();        //stu.tiao();        stu.pa();    }}
0 0
原创粉丝点击