1interface Child3{ 2 //private String uString; //不能出现变量 3 //private void f(); //不能出现私有成员方法 4// String string; 5// private String string2; 6// private transient String string3; 7// private strictfp String string21; 8// public String string4; 9 abstract void f(); 10 void f1(); 11 //protected void f2(); //不能出现保护成员方法 12 public void f3(); 13} 14 15class Child31 implements Child3{ 16 17 public void f() { // 实现接口,不论接口里的是默认权限方法还是public方法, 18 //都要写成public权限 19 // TODO Auto-generated method stub 20 21 } 22 23 public void f1() { 24 // TODO Auto-generated method stub 25 26 } 27 28 public void f3() { 29 // TODO Auto-generated method stub 30 31 } 32 33} 34 35abstract class Child4{ 36 String string; 37 private String string2; //在抽象类里存在私有变量和私有方法的意思是什么? 38 private transient String string3; 39// private strictfp String string21; //不能有strictfp修饰的成员变量 40 public String string4; 41 public static String string5; 42// public final String string6; //不能有final修饰的成员变量 43 44 abstract void f2(); 45 void f3(){} 46 private void f4() {} 47 protected void f5(){} 48 public void f6(){} 49 50} 51class Child41 extends Child4{ 52 53 @Override 54 void f2() { //必须要实现的 抽象类里的抽象方法 55 // TODO Auto-generated method stub 56 } 57 void f3(){} //覆盖 除去不能覆盖抽象类的私有方法,其他权限都可以进行覆盖 58 // 且权限向下开放 59 protected void f5(){} //如:f5 可以保留protected权限,也可以public 但是不能是默认权限 60 public void f6(){} //如:f6 就只能最开放的public权限 61 62 public static void main(String[] args) { 63 Child41 child41 = new Child41(); 64 child41.f2(); 65 child41.f3(); 66 child41.f5(); 67 child41.f6(); 68 child41.f3(); 69 70 System.out.println(child41.string+child41.string4); 71 } 72 73}
java 里的接口类和抽象类
Wesley13
2021-10-11
993 1 0
点赞
收藏
评论区
加载中...