摘要:
interface Show{ public void show();}class A{ void f(Show s){ s.show(); }}public class Example5_17 { public static void main(String[] args) {A a=new A(); a.f(new Show(){ public void show(){ System.out.println("这是实现了接口的匿名类"); } });}}public class Example5_18{public static void main(String arg 阅读全文
摘要:
public class Example5_14 { public static void main(String args[]) {Pillar pillar;Geometry tuxing;tuxing=new Lader(12,22,100);System.out.println("梯形的面积"+tuxing.getArea());pillar=new Pillar(tuxing,58);System.out.println("梯形底的柱体的体积"+pillar.getVolume());tuxing=new Circle(10);System.o 阅读全文
摘要:
class B implements Computable{public int f(int x){ return x*x*x;} public int g(int x,int y){ return x*y;}}public class Example5_11 {public static void main(String[] args) {A a=new A(); B b=new B(); System.out.println(a.MAX); System.out.println(""+a.f(10)+""+a.g(12, 6)); System.ou 阅读全文
摘要:
class A{double n;int m;void f(){ System.out.printf("子类继承方法f(),n=%f,m=%d\n",n,m);}void g(){ System.out.printf("你好,n=%f,m=%d\n",n,m);}}class B extends A{int n=12;void g(){ System.out.printf("子类重写方法g(),n=%d,m=%d\n",n,m);}void cry(){ System.out.printf("子类新增的方法,n=%d,m=% 阅读全文
摘要:
class A{ public int f(int x,int y){ return x+y; } } class B extends A{ public int f(byte x,int y){ return x*y; } } public class Example5_5{ public static void main(String args[]){ int z=0; B b=new B(); z=b.f(10,10); System.out.println(z); z=b.f((byte)10,10); System.out.println(z); } } cla... 阅读全文
摘要:
class Father{private int moneyDollar=300;int moneyHK=200;int add(int x,int y){return x+y;}}class Son extends Father{int moneyRMB=800;public void changMoneyHK(int x){moneyHK=x;}public void changMoneyRMB(int x){moneyRMB=x;}int subs(int x,int y){return x-y;}}class GrandSon extends Son{ int multi(int x, 阅读全文