您的位置:首页 > 编程语言 > Java开发

java中类的权限

2016-08-09 20:13 253 查看


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

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();

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java类权限