java 一个父类派生两个子类_RoundArea 1编写程序,在 中定义一个抽象类 、两个 类的派生子类Rect 类和 Java Develop 238万源代码下载- www.pudn.com...

详细说明:1编写程序,在程序中定义一个抽象类Area、两个Area类的派生子类RectArea类和RoundArea类,以及一个实现类ImpleArea类。程序的实现要求如下。

(1)抽象类Area类中只包含一个抽象方法:double area()。

(2)子类RoundArea类通过覆盖父类中的抽象方法area来求圆的面积,另一个子类RectArea类通过覆盖父类中的抽象方法area求长方形的面积。

(3)圆的半径和长方形的边分别定义为子类RoundArea类和RectArea类的域,都为double类型。

(4)ImpleArea类求出长2.1宽3.0的长方形和半径为4.0的圆的面积,并在屏幕上显示。

2.声明圆类Round,实现Area接口,计算圆面积。

-A program, the program defines an abstract class Area, the two Area class derived the subclass of RectArea Class and RoundArea of class, as well as a the implementation class ImpleArea class. The realization of the program requirements are as follows.

(1) Area class abstract class contains an abstract method: double area ().

(2) sub-class RoundArea of the coverage abstract methods in the parent class area of circular area another subclass RectArea of the abstract methods override the parent class area to find the area of a rectangle.

(3), respectively, the radius of the circle and rectangle edge is defined as the domain the the subclass of RoundArea Class and RectArea of class for type double.

(4) ImpleArea-class determined length 2.1 3.0 wide rectangular and a radius of the area of ​ ​ a circle of 4.0, and is displayed on the screen.

2. Statement circle Round, Area interface, calculate the area of ​ ​ a circle.

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是一个简单的示例代码: ```python class Computer: def __init__(self, brand, model): self.brand = brand self.model = model def display_info(self): print("Brand:", self.brand) print("Model:", self.model) class Laptop(Computer): def __init__(self, brand, model, weight): super().__init__(brand, model) self.weight = weight def display_info(self): super().display_info() print("Weight:", self.weight) class Desktop(Computer): def __init__(self, brand, model, monitor_size): super().__init__(brand, model) self.monitor_size = monitor_size def display_info(self): super().display_info() print("Monitor Size:", self.monitor_size) ``` 在上面的代码,我们定义了一个 `Computer` 类,它具有 `brand` 和 `model` 两个属性,以及一个 `display_info` 方法,用于显示计算机的信息。 然后,我们定义了两个子类 `Laptop` 和 `Desktop`,它们继承自 `Computer`。`Laptop` 类增加了一个 `weight` 属性,并重写了 `display_info` 方法,以便能够显示出计算机的重量。`Desktop` 类增加了一个 `monitor_size` 属性,并重写了 `display_info` 方法,以便能够显示出计算机的显示器尺寸。 这样,我们就可以创建 `Computer`、`Laptop` 和 `Desktop` 类的对象,并使用它们的方法来显示它们的信息了。具体示例如下: ```python computer = Computer("Dell", "OptiPlex 9020") computer.display_info() laptop = Laptop("Lenovo", "ThinkPad X1 Carbon", 1.13) laptop.display_info() desktop = Desktop("HP", "EliteDesk 800 G1", 24) desktop.display_info() ``` 输出结果如下: ``` Brand: Dell Model: OptiPlex 9020 Brand: Lenovo Model: ThinkPad X1 Carbon Weight: 1.13 Brand: HP Model: EliteDesk 800 G1 Monitor Size: 24 ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值