jialisoftw

java中类的继承与抽象类简明教程

  1. package Karl.Doenitz;    
  2. public class father {  
  3.     public int q;  
  4.     public father(){  
  5.         System.out.println(2);  
  6.     }  
  7.     public father(int k){  
  8.         System.out.println(k);  
  9.     }  
  10.     public int a(){  
  11.         return 1;  
  12.     }  
  13. }    
  14. package Karl.Doenitz;  
  15.   
  16. public class son extends father{  
  17.     public son(){  
  18.         System.out.println(3);  
  19.     }  
  20.     public son(int k){  
  21.         System.out.println(k+"new");  
  22.     }  
  23.     public void fun(int p){  
  24.         son s = new son();  
  25.         s.q=p;  
  26.         System.out.println(s.q);  
  27.     }  
  28.       public static void main(String args[]){  
  29.         son s = new son();  
  30.           son ss = new son(7);  
  31.           int l = s.a();  
  32.           s.fun(9);  
  33.           System.out.println(l);  
  34.       }  
  35. }    
  36. package Karl.Doenitz;   
  37. public abstract class karl {  
  38.     abstract void fun();  
  39. }  
  40. package Karl.Doenitz;  
  41.   
  42. public abstract  class doenitz extends karl{           
  43.         public static void main(String args[]){  
  44.             doenitz d = new doenitz(){  
  45.                 void fun() {  
  46.                     // TODO Auto-generated method stub  
  47.                     System.out.println("asdf");  
  48.                 }  
  49.             };  
  50.             d.fun();  
  51.         }  
  52. }  
    源文地址:
    http://www.heatpress123.net/cpzs/

posted on 2012-11-10 10:23 飞猪一号 阅读(150) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航:
 

导航

<2012年11月>
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

统计

常用链接

留言簿

随笔档案

友情链接

搜索

最新评论

阅读排行榜

评论排行榜