练习10.9-3

顶级父类

 1 package hello;
 2 
 3 public class Pc {
 4     
 5     public Pc()
 6     {
 7         System.out.println("电脑构造方法");
 8     }
 9 
10     String pinPai;
11     public void getPinpai(String pinpai)
12     {
13         pinPai = pinpai;
14         System.out.println("我的电脑品牌是:" + pinPai);
15     }
16     
17     
18     public void shangwang(String website)
19     {
20         System.out.println("我用电脑经常上的网站是:" + website);
21     }
22 }

父类

 1 package hello;
 2 
 3 public class Notebookpc extends Pc{
 4     
 5     public Notebookpc()
 6     {
 7         System.out.println("笔记本电脑构造方法");
 8     }
 9     
10     
11     
12     public void shangwang(String website)
13     {
14         System.out.println("我用笔记本经常上的网站是:" + website);
15     }
16 
17     
18 }

子类

 1 package hello;
 2 
 3 public class Supernbpc extends Notebookpc{
 4     
 5     public Supernbpc()
 6     {
 7         System.out.println("超级笔记本电脑构造方法");
 8     }
 9 
10     
11     public void shangwang(String website)
12     {
13         System.out.println("我用超级本经常上的网站是:" + website);
14     }
15 
16 }

构造子类实例

 1 package hello;
 2 
 3 public class Test1 {
 4 
 5     public static void main(String[] args) {
 6         
 7         // TODO Auto-generated method stub
 8         
 9         Supernbpc snb = new Supernbpc();
10         
11         snb.getPinpai("Acer");
12         snb.shangwang("ACFun");
13         
14         
15 
16     }
17     
18 
19 }

运行结果

可以看出构建顺序是:先顶级父类,然后是上一级父类,最后是子类

posted @ 2015-10-16 00:58  dirgo  阅读(162)  评论(0编辑  收藏  举报