Complete the code to declare an abstract class named Vehicle.
public [1] class Vehicle { public abstract void start(); }
The keyword abstract is used to declare an abstract class in Java.
Complete the code to make the Car class inherit from the abstract Vehicle class.
public class Car [1] Vehicle { @Override public void start() { System.out.println("Car started"); } }
In Java, a class inherits from another class using the extends keyword.
Fix the error in the code by completing the method declaration in the abstract class.
public abstract class Animal { public [1] void makeSound(); }
Abstract methods in an abstract class must be declared with the abstract keyword and have no body.
Fill both blanks to create a concrete class Dog that extends Animal and implements the makeSound method.
public class Dog [1] Animal { @Override public void makeSound() [2] { System.out.println("Bark"); } }
The class extends the abstract class, and the method body is enclosed in {}.
Fill all three blanks to create a concrete class Cat that extends Animal, implements makeSound, and adds a new method purr.
public class Cat [1] Animal { @Override public void makeSound() [2] { System.out.println("Meow"); } public void purr() [3] { System.out.println("Purr"); } }
The class extends Animal, and both methods have bodies enclosed in {}.