0
0
Javaprogramming~10 mins

Abstract classes in Java - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare an abstract class named Vehicle.

Java
public [1] class Vehicle {}
Drag options to blanks, or click blank then click option'
Afinal
Bprivate
Cstatic
Dabstract
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'final' instead of 'abstract' which prevents inheritance.
Using 'static' which is not valid for top-level classes.
Using 'private' which is an access modifier, not for abstract classes.
2fill in blank
medium

Complete the code to declare an abstract method named startEngine in the Vehicle class.

Java
public abstract class Vehicle {
    public [1] void startEngine();
}
Drag options to blanks, or click blank then click option'
Afinal
Babstract
Cstatic
Dprivate
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'final' which means the method cannot be overridden.
Using 'static' which is not allowed for abstract methods.
Using 'private' which prevents subclass access.
3fill in blank
hard

Fix the error in the code by completing the class declaration to make it abstract.

Java
public [1] {
    public abstract void startEngine();
}
Drag options to blanks, or click blank then click option'
Aabstract class Car
Bclass Car
Cfinal class Car
Dstatic class Car
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Leaving out 'abstract' causes a compilation error.
Using 'final' prevents subclassing which is needed for abstract methods.
Using 'static' is invalid for top-level classes.
4fill in blank
hard

Fill both blanks to complete the subclass Car that extends the abstract class Vehicle and implements the startEngine method.

Java
public class Car [1] Vehicle {
    @Override
    public void startEngine() [2]
}
Drag options to blanks, or click blank then click option'
Aextends
Bimplements
C()
D{}
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'implements' which is for interfaces, not classes.
Using parentheses instead of braces for method body.
5fill in blank
hard

Fill all three blanks to complete the abstract class Shape with an abstract method area, and a concrete method displayArea that prints the area.

Java
public abstract class Shape {
    public abstract double [1]();

    public void [2]() {
        System.out.println("Area: " + [3]());
    }
}
Drag options to blanks, or click blank then click option'
Aarea
BdisplayArea
DprintArea
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using different names for the method calls causing errors.
Not matching method names exactly.