AlgoMaster Logo

Abstraction - Quiz

Last Updated: January 3, 2026

1 min read

Abstraction Exercises

31 quizzes

1
Code Completion

Ensure this class cannot be instantiated directly because it serves only as a base for payment types

java
1
public class PaymentProcessor {

Click an option to fill the blank:

2
Code Completion

Allow this class to promise that it supports basic logging behavior defined elsewhere

java
1
public class ServiceLogger Loggable {

Click an option to fill the blank:

3
Code Completion

Declare a method in an interface that must be implemented by all task types

java
1
void executeTask

Click an option to fill the blank:

4
Multiple Choice

Which statement about abstract classes is true?

5
Multiple Choice

In an abstract class, what must a non-abstract (concrete) subclass do?

6
Multiple Choice

Which is a valid reason to use an interface instead of an abstract class?

7
Multiple Choice

Which keyword is used to declare an abstract method in an abstract class?

8
Multiple Choice

What is true about default methods in interfaces?

9
Multiple Choice

How are static methods in interfaces accessed?

10
Multiple Choice

Which statement about private methods in interfaces is correct?

11
Multiple Choice

What makes an interface a functional interface?

12
Multiple Choice

Which built-in interface is a classic example of a marker interface?

13
Multiple Choice

Why might you define your own marker interface?

14
Multiple Choice

Which is a valid declaration of a functional interface for processing orders?

15
Sequencing

Order the steps to define and use an abstract class for reporting different file formats

Drag and drop to reorder, or use the arrows.

16
Sequencing

Order the steps to create and use an interface for email notification sending

Drag and drop to reorder, or use the arrows.

17
Output Prediction

What is the output of this code using an abstract class reference?

1abstract class Shape {
2    abstract double area();
3}
4class Square extends Shape {
5    private double side;
6    Square(double side) { this.side = side; }
7    double area() { return side * side; }
8}
9public class Main {
10    public static void main(String[] args) {
11        Shape s = new Square(3);
12        System.out.println(s.area());
13    }
14}
18
Output Prediction

What is the output when a class implements an interface with a default method?

1interface Greeter {
2    default String greet() { return "Hello"; }
3}
4class FriendlyGreeter implements Greeter {
5}
6public class Main {
7    public static void main(String[] args) {
8        Greeter g = new FriendlyGreeter();
9        System.out.println(g.greet());
10    }
11}
19
Output Prediction

What is the output of calling a static interface method?

1interface MathUtils {
2    static int triple(int x) { return x * 3; }
3}
4public class Main {
5    public static void main(String[] args) {
6        System.out.println(MathUtils.triple(4));
7    }
8}
20
Output Prediction

What is the output when a default method uses a private helper in an interface?

1interface Formatter {
2    private String wrap(String s) { return "[" + s + "]"; }
3    default String formatName(String name) { return wrap(name.toUpperCase()); }
4}
5class NameFormatter implements Formatter { }
6public class Main {
7    public static void main(String[] args) {
8        Formatter f = new NameFormatter();
9        System.out.println(f.formatName("alice"));
10    }
11}
21
Output Prediction

What is the output when using a lambda with a functional interface?

1@FunctionalInterface
2interface Converter {
3    String convert(int value);
4}
5public class Main {
6    public static void main(String[] args) {
7        Converter c = v -> "Value:" + (v + 2);
8        System.out.println(c.convert(5));
9    }
10}
22
Bug Spotting

Find the bug in this code using an interface as a functional interface

Click on the line(s) that contain the bug.

java
1
@FunctionalInterface
2
interface Task {
3
    void run();
4
    void stop();
5
}
6
public class Main {
7
    public static void main(String[] args) {
8
        Task task = () -> System.out.println("Running");
9
    }
10
}
23
Bug Spotting

Find the bug in this code using a default method and a private helper in an interface

Click on the line(s) that contain the bug.

java
1
import java.util.Arrays;
2
interface Statistics {
3
    default double average(double[] data) {
4
        return sum(data) / data.length;
5
    }
6
    private static double sum(double[] data) {
7
        return Arrays.stream(data).sum();
8
    }
9
}
10
 
24
Matching

Match each interface feature with its primary purpose

Click an item on the left, then click its match on the right. Click a matched item to unmatch.

25
Matching

Match each abstraction concept to a realistic use case

Click an item on the left, then click its match on the right. Click a matched item to unmatch.

26
Fill in the Blanks

Complete the code for an interface with a default method that calculates the area of a circle using a provided radius

java
1
public interface CircleCalculator {
2
double radius();
3
4
default double () {
5
return Math.PI * * ;
6
}
7
}
8

Click an option to fill blank 1:

27
Fill in the Blanks

Complete the functional interface and its lambda usage to log a message with a prefix

java
1
@FunctionalInterface
2
interface Logger {
3
void (String msg);
4
}
5
public class Main {
6
public static void main(String[] args) {
7
Logger logger = m -> System.out.println("[INFO] " + m);
8
logger.("Started");
9
}
10
}
11

Click an option to fill blank 1:

28
Fill in the Blanks

Complete the interface to add a static factory method that creates a Greeting functional interface

java
1
@FunctionalInterface
2
interface Greeting {
3
void say(String name);
4
5
static Greeting (String prefix) {
6
return n -> System.out.println(prefix + ", " + n);
7
}
8
}
9
public class Main {
10
public static void main(String[] args) {
11
Greeting g = Greeting.("Welcome");
12
g.say("Sam");
13
}
14
}
15

Click an option to fill blank 1:

29
Fill in the Blanks

Complete the marker interface usage to control which entities are exportable

java
1
interface { }
2
3
class Product implements {
4
String name;
5
}
6
7
class AuditService {
8
boolean canExport(Object o) {
9
return o instanceof ;
10
}
11
}
12

Click an option to fill blank 1:

30
Hotspot Selection

Click the line that calls a default method from an interface reference

Click on the line to select.

java
1
interface Printer {
2
    default void print(String msg) {
3
        System.out.println("PRINT: " + msg);
4
    }
5
}
6
class ConsolePrinter implements Printer { }
7
public class Main {
8
    public static void main(String[] args) {
9
        Printer p = new ConsolePrinter();
10
        p.print("Ready");
11
    }
12
}
13
 
31
Hotspot Selection

Click the line that checks for a marker interface implementation

Click on the line to select.

java
1
interface Cacheable { }
2
class Session implements Cacheable { }
3
class Logger { }
4
public class Main {
5
    public static void main(String[] args) {
6
        Object o = new Session();
7
        boolean result = o instanceof Cacheable;
8
        System.out.println(result);
9
    }
10
}
11