0
0
Javaprogramming~10 mins

Abstract methods 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 method in an abstract class.

Java
abstract class Animal {
    abstract void [1]();
}
Drag options to blanks, or click blank then click option'
AmakeSound
Babstract
Cvoid
Dsound
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'void' as the method name instead of the return type.
Writing 'abstract' again inside the method declaration.
Using a variable name instead of a method name.
2fill in blank
medium

Complete the code to make the class abstract.

Java
public abstract class [1] {
    abstract void display();
}
Drag options to blanks, or click blank then click option'
Aabstract Dog
BDog
Cabstract
DAbstractDog
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Forgetting the 'abstract' keyword before the class name.
Trying to declare the class as 'AbstractDog' without the keyword.
Placing 'abstract' after the class name.
3fill in blank
hard

Fix the error in the abstract method declaration.

Java
abstract class Vehicle {
    [1] void move();
}
Drag options to blanks, or click blank then click option'
Astatic
Bpublic
Cabstract
Dfinal
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Leaving a method body for an abstract method.
Using 'static' or 'final' with abstract methods.
Not using the 'abstract' keyword.
4fill in blank
hard

Fill both blanks to correctly declare an abstract method in an abstract class.

Java
abstract class Shape {
    [1] [2] area();
}
Drag options to blanks, or click blank then click option'
Aabstract
Bdouble
Cvoid
Dpublic
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'void' as the return type for an abstract method that should return a value.
Forgetting the 'abstract' keyword.
Using access modifiers incorrectly.
5fill in blank
hard

Fill all three blanks to correctly declare an abstract method with public access and int return type.

Java
abstract class Calculator {
    [1] [2] [3]();
}
Drag options to blanks, or click blank then click option'
Aabstract
Bint
Ccalculate
Dpublic
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Placing 'abstract' after the method name.
Omitting the access modifier.
Using 'void' instead of 'int' as return type.