Question: 1 . Consider the code snippet below. This code models a simple hierarchy of Vehicle and Car classes. Vehicle is a general class containing color

1. Consider the code snippet below. This code models a simple hierarchy of Vehicle and Car classes. Vehicle is a general class containing color and speed as member fields and methods to accelerate and brake. Car is a specific type of Vehicle, and it inherits the properties and methods of Vehicle. It also contains an additional member field brand.Your task is to complete the missing portions of code in the snippet.Please note that missing codes in (A),(B),(C),(D), and (E) do not have to be limited to one line.[2*5=10 Marks]Expected Output of the java program is as follows:Vehicle Color: RedVehicle Speed: 0Accelerating... New Speed: 5Braking... New Speed: 0Car Color: BlueCar Speed: 0Car Brand: ToyotaAccelerating... New Speed: 5Braking... New Speed: 0 Java code:class Vehicle { private String color; private int speed; public Vehicle(String color){ this.color = color; this.speed =0; } public void accelerate(){/*___MISSING CODE (A)___*/ System.out.println("Accelerating... New Speed: "+ speed); } public void brake(){/*___MISSING CODE (B)___*/ System.out.println("Braking... New Speed: "+ speed); } public String getColor(){return color; } public int getSpeed(){return speed; }} class Car extends /*___MISSING CODE (C)___*/{ private String brand; public Car(String color, String brand){/*___MISSING CODE (D)___*/ this.brand = brand; } public String getBrand(){ return brand; }} public class Main { public static void main(String[] args){ Vehicle vehicle = new Vehicle("Red"); System.out.println("Vehicle Color: "+/*___MISSING CODE (E)___*/); System.out.println("Vehicle Speed: "+ vehicle.getSpeed()); vehicle.accelerate(); vehicle.brake(); Car car = new Car("Blue", "Toyota"); System.out.println("Car Color: "+ car.getColor()); System.out.println("Car Speed: "+ car.getSpeed()); System.out.println("Car Brand: "+ car.getBrand()); car.accelerate(); car.brake(); }}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!