extendstest.java
来自「java程序设计 清华出版社 孙燮华老师编写的程序源代码」· Java 代码 · 共 24 行
JAVA
24 行
//extendsTest.java
class c1{
int x=25;
private int y;
protected void print1(){
System.out.println("This is protected method. It can be extended.");
}
private void print2(){
System.out.println("This is private method.");
}
}
class extendsTest extends c1{
public static void main(String[] args){
c1 p = new c1();
System.out.println("p.x = "+p.x);
//System.out.println("p.y = "+p.y);//错误! y has private access in c1
p.print1();
//p.print2(); //错误! pirnt2() has private access in c1
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?