Java Intermediate

0% completed

Previous
Next
Quiz
Question 1
What does abstraction in Java mean?
A
Inheriting methods and fields from another class.
B
Hiding the internal implementation details and showing only essential features.
C
Overriding methods in a subclass.
D
Combining multiple classes into one.
Question 2
Which statement about nested interfaces is true?
A
Nested interfaces are defined within a class or another interface to logically group related interfaces.
B
Nested interfaces must be private.
C
A nested interface cannot be implemented by any class.
D
Nested interfaces can only contain default methods.
Question 3
Consider the following code snippet that involves abstraction:
abstract class Animal {
    abstract void makeSound();
}

class Cat extends Animal {
    void makeSound() {
        System.out.println("Meow");
    }
}

public class Test {
    public static void main(String[] args) {
        Animal a = new Cat();
        a.makeSound();
    }
}
What is demonstrated by this code?
A
Abstract classes cannot have abstract methods.
B
Abstract classes cannot be instantiated directly but can be used as references.
C
Abstract classes must always implement all methods from an interface.
D
A subclass cannot override methods from its abstract superclass.

.....

.....

.....

Like the course? Get enrolled and start learning!
Previous
Next