0
0
Javaprogramming~5 mins

Abstract methods in Java - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is an abstract method in Java?
An abstract method is a method declared without a body (no implementation) using the abstract keyword. It must be implemented by subclasses.
Click to reveal answer
beginner
Can you create an object of a class that contains an abstract method?
No, you cannot create an object of a class that has abstract methods because such a class is abstract and incomplete.
Click to reveal answer
beginner
How do you declare an abstract method in Java?
Use the abstract keyword before the method signature and do not provide a method body. For example: abstract void myMethod();
Click to reveal answer
intermediate
What must a subclass do if its superclass has abstract methods?
The subclass must provide concrete implementations (bodies) for all inherited abstract methods, or it must also be declared abstract.
Click to reveal answer
intermediate
Why use abstract methods in Java?
Abstract methods define a contract for subclasses, ensuring they implement specific behaviors while allowing different implementations.
Click to reveal answer
Which keyword is used to declare an abstract method in Java?
Aprivate
Babstract
Cstatic
Dfinal
Can an abstract method have a method body in Java?
AOnly if the class is abstract
BYes, always
CNo, never
DOnly if the method is static
What happens if a subclass does not implement all abstract methods from its abstract superclass?
AThe subclass must be declared abstract
BThe program runs but throws an error at runtime
CIt compiles without errors
DThe abstract methods are ignored
Can you instantiate an abstract class directly?
ANo, abstract classes cannot be instantiated
BYes, if it has no abstract methods
CYes, but only inside the same package
DOnly if the constructor is public
Which of the following is true about abstract methods?
AThey are always static
BThey can be private
CThey can have multiple implementations in the same class
DThey must be implemented by subclasses
Explain what an abstract method is and why it is useful in Java.
Think about how abstract methods help define rules for subclasses.
You got /4 concepts.
    Describe the rules a subclass must follow when inheriting abstract methods.
    Focus on subclass responsibilities with abstract methods.
    You got /3 concepts.