0
0
Javaprogramming~10 mins

Why abstraction is required in Java - Test Your Understanding

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 in Java.

Java
public [1] class Vehicle {
    abstract void start();
}
Drag options to blanks, or click blank then click option'
Astatic
Bfinal
Cabstract
Dprivate
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'final' instead of 'abstract' to declare an abstract class.
Trying to instantiate an abstract class.
2fill in blank
medium

Complete the code to declare an abstract method inside an abstract class.

Java
public abstract class Animal {
    public [1] void sound();
}
Drag options to blanks, or click blank then click option'
Aabstract
Bstatic
Cfinal
Dprivate
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Adding a method body to an abstract method.
Using 'static' or 'final' keywords with abstract methods.
3fill in blank
hard

Fix the error in the code by completing the class declaration to use abstraction properly.

Java
public [1] class DisplayClass {
    abstract void display();
}
Drag options to blanks, or click blank then click option'
Astatic
Bfinal
Cprivate
Dabstract
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Declaring a class with abstract methods as a normal class.
Using 'final' or 'static' keywords incorrectly with abstract classes.
4fill in blank
hard

Fill both blanks to complete the code that shows why abstraction is required by hiding details.

Java
abstract class [1] {
    abstract void [2]();
}

class Car extends Vehicle {
    void start() {
        System.out.println("Car started");
    }
}
Drag options to blanks, or click blank then click option'
AVehicle
Brun
Cstart
DEngine
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using method names that do not match subclass implementations.
Naming the abstract class incorrectly.
5fill in blank
hard

Fill all three blanks to complete the code demonstrating abstraction by hiding complex details.

Java
abstract class [1] {
    abstract void [2]();
}

class [3] extends Device {
    void operate() {
        System.out.println("Device operating");
    }
}
Drag options to blanks, or click blank then click option'
ADevice
Boperate
CSmartphone
Dstart
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Mismatch between method names in abstract class and subclass.
Incorrect subclass name that does not extend the abstract class.