0
0
Javaprogramming~10 mins

Abstract vs concrete classes in Java - Interactive 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 {
    public abstract void start();
}
Drag options to blanks, or click blank then click option'
Astatic
Bfinal
Cabstract
Dpublic
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'final' instead of 'abstract' to declare the class.
Forgetting to use any keyword and making it a concrete class.
2fill in blank
medium

Complete the code to make the Car class inherit from the abstract Vehicle class.

Java
public class Car [1] Vehicle {
    @Override
    public void start() {
        System.out.println("Car started");
    }
}
Drag options to blanks, or click blank then click option'
Aextends
Binherits
Cimplements
Duses
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'implements' instead of 'extends' for class inheritance.
Using a non-existent keyword like 'inherits'.
3fill in blank
hard

Fix the error in the code by completing the method declaration in the abstract class.

Java
public abstract class Animal {
    public [1] void makeSound();
}
Drag options to blanks, or click blank then click option'
Afinal
Babstract
Cstatic
Dprivate
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'final' or 'static' keywords with abstract methods.
Forgetting to mark the method as abstract.
4fill in blank
hard

Fill both blanks to create a concrete class Dog that extends Animal and implements the makeSound method.

Java
public class Dog [1] Animal {
    @Override
    public void makeSound() [2] {
        System.out.println("Bark");
    }
}
Drag options to blanks, or click blank then click option'
Aextends
B()
C{}
Dimplements
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'implements' instead of 'extends' for class inheritance.
Using parentheses instead of curly braces for method body.
5fill in blank
hard

Fill all three blanks to create a concrete class Cat that extends Animal, implements makeSound, and adds a new method purr.

Java
public class Cat [1] Animal {
    @Override
    public void makeSound() [2] {
        System.out.println("Meow");
    }
    public void purr() [3] {
        System.out.println("Purr");
    }
}
Drag options to blanks, or click blank then click option'
Aextends
B()
C{}
Dimplements
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'implements' instead of 'extends' for class inheritance.
Using parentheses instead of curly braces for method bodies.