具体要求使用 Eclipse 创建项目

具体要求使用 Eclipse 创建项目:运用面向对象的思想实现相应功能: A 能够创建父类,子类实现够承完成类的封装、创建抽象类和抽象方法 C .运用多态的思想实现功能升级

这个其实不难,应该是作业吧,按照要求即可


public class 继承测试 {
	/*
	在该类中定义两个方法,一个是 getName,用于使用反射机制获得类名称;另一个是抽象方法 getArea ,用来计算图形的面积。
	(2)创建圆形类 Circle ,继承自 Shape ,并实现抽象方法getArea。
	在 Circle 类的构造方法中获得了圆形的半径,用于在getArea计算圆形的面积。
	(3)创建矩形类 Rectangle ,继承自 Shape ,
	并实现抽象方法 getArea 。在 Rectangle 类的构造方法中获得了矩形的长和宽,用于在 getArea计算矩形的面积。
	
	*/
	public static void main(String[] args) {
		Shape circle= new Circle(10);
		System.out.println("类名称是:"+circle.getName());
		System.out.println("圆的面积="+circle.getArea());
		Shape rect = new Rectangle(10,20);
		System.out.println("类名称是:"+rect.getName());
		System.out.println("矩形的面积="+rect.getArea());

	}
}
abstract class Shape{
	String getName() {
		return this.getClass().getName();
	}
	abstract float getArea();
}
class Circle extends Shape{

	float r;
	public Circle() {};
	public Circle(float r) {
		this.r = r;
	}
	
	@Override
	float getArea() {
		
		return 3.14f*r*r;
	}
	
}
class Rectangle extends Shape{

	float width;
	float height;
	public Rectangle() {}
	public Rectangle(float width,float height) {
		this.width = width;
		this.height = height;
	}
	@Override
	float getArea() {
		
		return width*height;
	}
	
}