Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question 16 4 poin Write a JAVA code to implement a class named Vehicle, and its subclass called Car. The details of the classes are
Question 16 4 poin Write a JAVA code to implement a class named Vehicle, and its subclass called Car. The details of the classes are described in the following UML diagram Vehicle -id : int +Vehicle +Vehicle(id : int) +getID : int +setId(id : int) : void +toString(): String Car -brand : String -color: String +Car(id : int, brand : String, color : String) +toString(): String For Vehicle class: - In the constructor Vehicle(id: int), use this keyword to initialize the attribute id. - The toString() should override the toString() of the object class. It should return the id of the vehicle. For example: Vehicle (id = 1001) For Car class: - Use super keyword to invoke the superclass constructor to pass the id. - Use this keyword to initialize the attributes brand and color. Override the Loslring() method to return the id, brand and color. Use super keyword to invoke the Lostring() of the super class for the id. For example: car : Vehicle (id = 1001), brand = Toyota, color = Red
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started