- class grandFather
- {
- String gF="爷爷";
- void showGF()
- {
- System.out.println(gF);
- }
- }
- class father extends grandFather
- {
- String F="爸爸";
- void showF()
- {
- System.out.println(F);
- }
- }
- class me extends father
- {
- String M="我";
- void showM()
- {
- System.out.println(M);
- }
- }
- public class Demo
- {
- public static void main(String[] args)
- {
- me m =new me();
- m.showM();
- m.showF();
- m.showGF();
- }
- }
复制代码 如果父类的父类没有被覆盖和私有的化,子类的子类都会继承下来,只要直接调用即可。 |