Tạo đối tượng từ lớp trừu tượng

Em mới học java được giao 1 bài tập như sau:

Create project Java application named Computer System

  1. Create package named com.bkap.machine and create some classes in this package following.
  2. Create an abstract class named Computer that stores the following details:
  • name: String data type, named machine (ex: Elitebook 2670p).
  • manufac: String data type, named manufacturer (ex: Sony Vaio).
  • price: float data type, price of computer (ex: 123.99).
  • warranty: integer data type, warranty months of computer (ex: 12).
  1. In this class, create two abstract methods named inputData() and printInfo().
  2. Create two class named HPComputer and DellComputer is extended from Computer class. In classes
    above, override two methods inputData() for input data and printInfo() for show data of computer (write code
    with same function input and output in method).
  3. Create a Java main class named ComputerManager has method print menu as following:
    …: MENU :…
  4. Input computer list.
  5. View computer list.
  6. Sort computer list by warranty.
  7. Sort computer list by name.
  8. Exit.
  9. In this class, create a array containable 5 Computer and create methods implement some tasks
    which follow menu above:
  • Input list (ask for user want HP or Dell then create object by same class)

Em có thắc mắc về đoạn “create a array containable 5 Computer” vì không thể tạo 1 đối tượng từ 1 lớp trừu tượng

Cái đó ý là khai báo 1 mảng 5 phần tử Computer. Khai báo thì chưa cần khởi tạo đối tượng, khi nhập vào thì mới hỏi tạo HP hay Dell.

5 Likes

Cảm ơn a. e hiểu rồi

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?