What is abstraction in Java?
A
Hiding implementation details and showing only functionality
B
Combining classes into packages
C
Writing multiple classes
D
Executing Java bytecode
Analysis & Theory
Abstraction hides the complex implementation and exposes only the essential features.
Which keyword is used to declare an abstract class?
Analysis & Theory
The `abstract` keyword is used to declare an abstract class.
Which of the following statements about abstract classes is TRUE?
A
An abstract class can be instantiated
B
An abstract class must have at least one abstract method
C
An abstract class can have both abstract and non-abstract methods
D
An abstract class cannot have constructors
Analysis & Theory
Abstract classes can have both abstract methods (without body) and concrete methods (with implementation).
What must a subclass do if it inherits an abstract class with abstract methods?
A
Implement all abstract methods
B
Ignore the abstract methods
C
Call the abstract methods
Analysis & Theory
A concrete subclass must provide implementations for all inherited abstract methods.
Which keyword is used to declare an abstract method?
Analysis & Theory
Abstract methods are declared using the `abstract` keyword and have no body.
Can an interface have concrete (non-abstract) methods in Java 8 and later?
B
Yes, using default methods
D
No, interfaces cannot have methods
Analysis & Theory
Java 8 introduced default methods in interfaces that have concrete implementations.
What is the main difference between abstract classes and interfaces?
A
Abstract classes can have constructors; interfaces cannot
B
Interfaces can have instance variables; abstract classes cannot
C
Abstract classes cannot have concrete methods
D
Interfaces support multiple inheritance of implementation
Analysis & Theory
Abstract classes can have constructors and instance variables; interfaces cannot have constructors.
What happens if a class does not implement all methods of an interface it implements?
A
It compiles without error
B
It must be declared abstract
D
It ignores the missing methods
Analysis & Theory
The class must be declared abstract if it doesn’t implement all interface methods.
Which of the following can have instance variables?
Analysis & Theory
Abstract classes can have instance variables; interfaces cannot have instance variables (only constants).
What is true about abstract classes?
B
They can be instantiated
C
They can have both abstract and concrete methods
Analysis & Theory
Abstract classes can contain both abstract methods and concrete (implemented) methods.