final super
/javaDemo3/src/com/imooc/Animal.java
package com.imooc; public class Animal { public int age = 10; public String name; public void eat() { System.out.println("年龄:"+age+ "动物可以吃东西" ); } public Animal() { age = 20; System.out.println("Animal类执行了" ); } }
/javaDemo3/src/com/imooc/Dog.java
package com.imooc; public class Dog extends Animal { public int age = 20; public void eat() { System.out.println("年龄:"+age+ "狗可以吃东西" ); } public Dog() { System.out.println("Dog类执行了" ); } public void method() { System.out.println(age); System.out.println("super" + super.age); eat(); super.eat(); } }
/javaDemo3/src/com/imooc/Initail.java
package com.imooc; public class Initail { public static void main(String[] args) { // TODO Auto-generated method stub Animal animal = new Animal(); System.out.println("animal的age:" + animal.age ); Dog dog = new Dog(); dog.age = 10; dog.name = "aa"; dog.eat(); dog.method(); } }
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/73130.html
摘要:类方法代码类执行了重写方法右键类执行了两个对象是相等的两个对象是不相等的重写右键年龄狗可以吃东西类执行了两个对象是相等的两个对象是不相等的 Object类 showImg(https://segmentfault.com/img/bVbnBZ2?w=1234&h=657); toString()方法 showImg(https://segmentfault.com/img/bVbnBZ...
摘要:中的继承初始化顺序父类和子类年龄动物可以吃东西类执行了年龄狗可以吃东西类执行了对象的属性和构造方法年龄动物可以吃东西类执行了的 java中的继承初始化顺序 showImg(https://segmentfault.com/img/bVbnBI1?w=1277&h=671); showImg(https://segmentfault.com/img/bVbnBKG?w=811&h=427...
java中的继承 showImg(https://segmentfault.com/img/bVbnByS?w=1155&h=726); showImg(https://segmentfault.com/img/bVbnByR?w=1146&h=708); showImg(https://segmentfault.com/img/bVbnByT?w=1152&h=701); showImg(htt...
java中的方法重写 showImg(https://segmentfault.com/img/bVbnBEj?w=1260&h=668); 重写前 showImg(https://segmentfault.com/img/bVbnBEu?w=347&h=158); /javaDemo3/src/com/imooc/Animal.java package com.imooc; public cl...
摘要:人类说话中国人说汉语,美国人说英语继承实现人类具有说话的能力中国人说汉语美国人说英语抽象类实现中国人说汉语美国人说英语 人类说话,中国人说汉语,美国人说英语 showImg(https://segmentfault.com/img/bVbnFaM?w=305&h=188); 继承实现 /javaDemo6/src/com/imooc/Person.java package com.im...
阅读 3637·2021-10-11 11:09
阅读 1318·2021-09-24 10:35
阅读 3402·2021-07-29 13:48
阅读 422·2019-08-30 13:15
阅读 2486·2019-08-30 12:53
阅读 3106·2019-08-30 12:44
阅读 2673·2019-08-29 16:57
阅读 942·2019-08-29 12:26