📄 mylab1.java
字号:
package j02080201.Pack1;
import java.lang.*;
public class myLab1
{
public void testfun()
{ //测试直接存取 animal 类内定义的成员
/* 整段都会有错误
System.out.println("in myLab1 IQ = " + IQ);
setIQ(60); //public
System.out.println("in myLab1 LabArea = " + LabArea);
System.out.println("in myLab1 DNA = " + DNA);
System.out.println("in myLab1 height = " + height); //public
System.out.println("in myLab1 weight = " + weight); //public
*/
System.out.println("myLab1 不是 animal 的子孙类,\n"
+ "不具有 animal 类的成员");
}
public static void main(String para[])
{ //测试使用 animal 类对象的成员
animal Obj3 = new animal();
Obj3.height = 165;
Obj3.weight = 50;
//System.out.println("Obj3.IQ = " + Obj3.IQ); //错误, private 成员只在 animal 内可见
Obj3.setIQ(140); //改用 public 接口函数
System.out.println("Obj3.LabArea = " + Obj3.LabArea);
System.out.println("Obj3.DNA = " + Obj3.DNA);
//myLab1 和 animal 在同一个 package,可使用 protected 成员
System.out.println("Obj3.height = " + Obj3.height);
System.out.println("Obj3.weight = " + Obj3.weight);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -