出10道基础的Java子类继承的题目
时间: 2024-05-31 08:11:09 浏览: 11
1. 编写一个Animal类,具有属性name和age,以及方法eat()和sleep()。编写一个Dog类继承自Animal类,并具有属性breed和方法bark()。
2. 编写一个Shape类,具有属性color和方法draw()。编写Circle和Square类分别继承Shape类,并具有属性radius和sideLength,以及方法calculateArea()。
3. 编写一个Employee类,具有属性name和salary,以及方法work()。编写一个Manager类继承自Employee类,并具有属性bonus和方法manage()。
4. 编写一个Person类,具有属性name、age和gender,以及方法eat()和sleep()。编写一个Student类继承自Person类,并具有属性grade和方法study()。
5. 编写一个Vehicle类,具有属性brand、model和price,以及方法start()和stop()。编写一个Car类继承自Vehicle类,并具有属性numOfDoors和方法drive()。
6. 编写一个Fruit类,具有属性name和color,以及方法ripe()。编写一个Apple类继承自Fruit类,并具有属性taste和方法makeJuice()。
7. 编写一个Product类,具有属性name、price和description,以及方法sell()。编写一个Book类继承自Product类,并具有属性author和method read()。
8. 编写一个House类,具有属性address、numOfRooms和price,以及方法rent()和sell()。编写一个Apartment类继承自House类,并具有属性numOfFloors和方法clean()。
9. 编写一个BankAccount类,具有属性balance和methods deposit()和withdraw()。编写一个CheckingAccount类继承自BankAccount类,并具有属性overdraft和方法transfer()。
10. 编写一个Animal类,具有属性name、age和gender,以及方法eat()和sleep()。编写一个Bird类继承自Animal类,并具有属性wingSpan和方法fly()。
相关推荐
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)