发布网友 发布时间:2022-04-26 20:29
共1个回答
热心网友 时间:2023-10-29 18:06
public class Demo { public static void main(String[] args) { A a=new B(); System.out.println(a.re()); a=new C(); System.out.println(a.re()); a=new D(); System.out.println(a.re()); } } abstract class A{ abstract int re(); } class B extends A{ int a=3; int re() { return a*a; } } class C extends B{ int b=4; int re() { return a*b; } } class D extends A{ int r=5; int re() { return (int)Math.PI*r*r; } }
热心网友 时间:2023-10-29 18:06
public class Demo { public static void main(String[] args) { A a=new B(); System.out.println(a.re()); a=new C(); System.out.println(a.re()); a=new D(); System.out.println(a.re()); } } abstract class A{ abstract int re(); } class B extends A{ int a=3; int re() { return a*a; } } class C extends B{ int b=4; int re() { return a*b; } } class D extends A{ int r=5; int re() { return (int)Math.PI*r*r; } }