- class Fu
- {
- private int num= 4;
- public void setNum(int num)
- {
- this.num=num;
- }
- public int getNum()
- {
- return this.num;
- }
- }
- class Zi extends Fu
- {
- private int num=5;
- int num1=getNum();
- //show1();
- void show()
- {
- System.out.println(num+"......"+num1+"......"+getNum());
- }
- static void show1()
- {
- System.out.println("hello world");
- }
- }
- class RunIt
- {
- public static void main(String[] args)
- {
- Zi z=new Zi();
- z.setNum(7);
- z.show();
- z.show1();
- show1();
- }
- static void show1()
- {
- System.out.println("hello Java");
- }
- }
复制代码 视频看到父子类的特点, 随便写了几句测试一下.
猜猜运行结果是什么?
另外问题是 一个类中是不是一定要有主函数才能调用本类的方法?
Zi类中 getNum()可以调用, 为什么写上show1()就编译失败了呢? 求指教
int num1=getNum();
//show1();
|
|