设为首页 加入收藏

TOP

Java接口与继承
2015-12-01 14:11:48 来源: 作者: 【 】 浏览:16
Tags:Java 接口 继承

Java接口与继承


class Grandparent {
?public Grandparent() {
? ? ? ? System.out.println("GrandParent Created.");
? ? }
? ? public Grandparent(String string) {
? ? ? ? System.out.println("GrandParent Created.String:" + string);
? ? }
}
class Parent extends Grandparent {
? ? public Parent() {
? ? ? ? //super("Hello.Grandparent.");
? ? ? ? System.out.println("Parent Created");
? ? ? // super("Hello.Grandparent.");
? ? }
}
class Child extends Parent {
? ? public Child() {
? ? ? ? System.out.println("Child Created");
? ? }
}
public class TestInherits {
? ? public static void main(String args[]) {
? ? ? ? Child c = new Child();
? ? }
}


Java接口与继承


public为共有类,子继承父母,父母继承祖父母
通过 super 调用基类构造方法,必须是子类构造方法中的第一个语句。


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Java多态与异常处理 下一篇Python之字符串格式化(format)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: