标签:
1 package $interface; 2 3 public interface ILeaveHome { 4 public abstract int a(); 5 public abstract int b(); 6 public abstract int c(); 7 public abstract int d(); 8 9 }
1 package $interface; 2 3 public abstract class AbstractTools { 4 private String abs01;//private的要设置访问器,外部的才可以访问 5 private String abs02; 6 public AbstractTools(String abs01,String abs02) 7 { 8 this.abs01=abs01; 9 this.abs02=abs02; 10 } 11 12 public void tools1() { 13 System.out.println("zzw abstract"); 14 } 15 public abstract int tool2(); 16 17 18 public void setAbs01(String abs01) 19 { 20 this.abs01=abs01; 21 } 22 public String getAbs01() 23 { 24 return abs01; 25 } 26 public void setAbs02(String abs02) 27 { 28 this.abs02=abs02; 29 } 30 public String getAbs02() 31 { 32 return abs02; 33 } 34 }
1 package $interface; 2 3 public class LeaveHomeImpl extends AbstractTools implements ILeaveHome{ 4 5 6 public LeaveHomeImpl(String a,String b){ 7 super(a, b);//调用父类的构造方法 8 9 10 } 11 public int tool2(){ 12 int a=6666; 13 return a; 14 15 } 16 public int a(){ 17 int a=1; 18 return a; 19 } 20 public int b(){ 21 int b=1; 22 return b; 23 } 24 public int c(){ 25 int c=1; 26 return c; 27 } 28 public int d(){ 29 int d=1; 30 return d; 31 } 32 33 public static void main(String args[]) 34 { 35 String z="z"; 36 String z6="z6"; 37 LeaveHomeImpl home=new LeaveHomeImpl(z,z6); 38 System.out.println("home.a()="+home.a()); 39 System.out.println("home.b()="+home.b()); 40 System.out.println("home.c()="+home.c()); 41 System.out.println("home.d()="+home.d()); 42 System.out.println("home.tool2()="+home.tool2()); 43 System.out.println("getAbs01="+home.getAbs01()); 44 System.out.println("getAbs02="+home.getAbs02()); 45 home.tools1(); 46 47 } 48 49 50 }
1 package $interface; 2 3 public class LeaveHomeTwice extends LeaveHomeImpl{ 4 String a; 5 String b; 6 7 public LeaveHomeTwice(){//第一种构造方式, 8 9 super("a","b");//传值进去的时候会自动调用父类的有参数的构造方法 10 11 } 12 public LeaveHomeTwice(String a,String b){//带参数的构造方法,体现了构造方法的overload,构造方法的重载 13 14 super(a,b);//改变了父类的值 15 16 } 17 //方法的override,方法的覆盖,对父类的覆盖 18 public int tool2(int a){ 19 20 int zzw; 21 zzw=a; 22 return zzw; 23 24 } 25 26 public static void main(String args[]) 27 { 28 int num=123; 29 LeaveHomeTwice a=new LeaveHomeTwice();//对应第一种构造方式 30 //LeaveHomeTwice a=new LeaveHomeTwice("zzwtwice","aiguotwice");//对应第二种构造方式 31 System.out.println(a.a()+"\t"+a.b()+"\t"+a.c()+"\t"+a.d()+"\t"+a.tool2(num)); 32 33 34 a.tools1(); 35 System.out.println("getAbs01:"+a.getAbs01()); 36 System.out.println("getAbs02:"+a.getAbs02()); 37 38 39 } 40 41 }
标签:
原文地址:http://www.cnblogs.com/zzzzw/p/4963674.html