Ask Question
15 August, 17:31

What is output?

public abstract class Vehicle {

public abstract void move (int miles);

public void printInfo ({

System. out. print ("Vehicle ");

public class Car extends Vehicle {

private int distance;

public void move (int miles) {

distance = distance + miles;

public void printInfo () {

System. out. print ("Car ");

}

public static void main (String args[]) {

Vehicle myVehicle;

Car myCar;

myVehicle = new Vehicle ();

myCar = new Car ();

myVehicle. printInfo ();

myCar. printInfo ();

}

}

Error: Car is not abstract and does not override abstract method move ()

Vehicle

Vehicle Car

Error: Vehicle is abstract and cannot be instantiated

+3
Answers (1)
  1. 15 August, 18:18
    0
    The output is:

    Error: Vehicle is abstract and cannot be instantiated

    Explanation:

    The following statement is causing this error:

    myVehicle = new Vehicle ();

    Here an instance of Vehicle is being created. The name of the instance is myVehicle. new keyword is used to create an object or instance of class like here the instance myVehicle of class Vehicle is being created.

    This instance cannot be created because the Vehicle is an abstract class. As you can see this statement public abstract class Vehicle.

    So Vehicle class is declared with abstract keyword which means that this is an abstract class and cannot be instantiated. So Vehicle class is an abstract class and abstract class can only be used as a base class for its derived classes. Vehicle just provides with the basic functionality that its sub or derived class like Car can implement.

    This class can be extended or inherited but no instance can be created of this class, as the Car class is used to extend the functionality of Vehicle class. Now you can create instance of Car class but NOT of a Vehicle class because it is an abstract class.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “What is output? public abstract class Vehicle { public abstract void move (int miles); public void printInfo ({ System. out. print ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers