public abstract class TestTable { public abstract float getArea(float r);}public class A extends TestTable { // Rect public float getArea(float r) { float area = r * r; return area; } }public class B extends TestTable { // Circle public float getArea(float r) { float area = (float) (Math.PI * r * r); return area; } }
仅供参考,希望还是自己试着写写 public abstract class Shape{ public abstract float getArea(float r); } public class Rect extends Shape{ public float getArea(float r) { float area = r * r; return area; } } public class Circle extends Shape{ public float getArea(float r) { float area = (float) (Math.PI * r * r); return area; } } public class Test { public static void main(String[] args){ Rect rt=new Rect(); System.out.println(rt.getArea(12)); Circle cl=new Circle(); System.out.println(cl.getArea(12)); }}
public abstract class Shape {
public abstract double Getarea(double length);
} public class Rect extends Shape { public double Getarea(double length){ return length*length; }} public class Circle extends Shape { final double PI=3.14; public double Getarea(double length){ return PI*length*length; } } public class Test { public static void main(String[] args) { Rect Jie = new Rect(); Circle S = new Circle(); System.out.println(S.Getarea(1)); System.out.println(Jie.Getarea(6)); } }
public interface Shape { double Getarea(double length);} public class Circle implements Shape { private final double PI = 3.14; public double Getarea(double length) { return PI * length * length / 4; }} public class Rect implements Shape { public double Getarea(double length) { return length * length; } } public class Test { public static void main(String[] args) { Rect Jie = new Rect(); Circle S = new Circle(); System.out.println(Jie.Getarea(2)); System.out.println(S.Getarea(6)); } }
public abstract class TestTable {
public abstract float getArea(float r);}public class A extends TestTable {
// Rect
public float getArea(float r) {
float area = r * r;
return area;
}
}public class B extends TestTable {
// Circle
public float getArea(float r) {
float area = (float) (Math.PI * r * r);
return area;
}
}
public abstract class Shape{
public abstract float getArea(float r); } public class Rect extends Shape{
public float getArea(float r) {
float area = r * r;
return area;
}
} public class Circle extends Shape{
public float getArea(float r) {
float area = (float) (Math.PI * r * r);
return area;
}
}
public class Test {
public static void main(String[] args){
Rect rt=new Rect();
System.out.println(rt.getArea(12));
Circle cl=new Circle();
System.out.println(cl.getArea(12));
}}
public abstract double Getarea(double length);
}
public class Rect extends Shape {
public double Getarea(double length){
return length*length;
}}
public class Circle extends Shape {
final double PI=3.14;
public double Getarea(double length){
return PI*length*length;
}
}
public class Test {
public static void main(String[] args) {
Rect Jie = new Rect();
Circle S = new Circle();
System.out.println(S.Getarea(1));
System.out.println(Jie.Getarea(6));
}
}
double Getarea(double length);}
public class Circle implements Shape {
private final double PI = 3.14; public double Getarea(double length) {
return PI * length * length / 4;
}}
public class Rect implements Shape {
public double Getarea(double length) {
return length * length;
}
}
public class Test {
public static void main(String[] args) {
Rect Jie = new Rect();
Circle S = new Circle();
System.out.println(Jie.Getarea(2));
System.out.println(S.Getarea(6));
}
}