Last Updated: January 13, 2026
21 quizzes
Mark a utility method so it can be called without creating an instance of the Utility class
public int max(int a, int b) { return a > b ? a : b; }Click an option to fill the blank:
Declare that the PaymentConfig reference cannot point to a different object after initialization
private PaymentConfig config = new PaymentConfig();Click an option to fill the blank:
Which statement best describes a Java object?
What happens if you define no constructor in a class?
Which access modifier restricts a field so it is only visible within its own class?
Why are fields commonly declared private with public getters and setters?
What is a key characteristic of a record class in Java?
What is the effect of declaring a method as final?
Which situation is a typical use case for an anonymous class?
Which keyword allows code in an inner class to refer unambiguously to the enclosing instance?
Which statement about instance initializer blocks is true?
Order the steps to define and use a simple inner member class to print a User's full name
Drag and drop to reorder, or use the arrows.
What is the output of this code using a constructor and this keyword?
1class User {
2 private String name;
3 public User(String name) {
4 this.name = name;
5 }
6 public String getName() {
7 return name;
8 }
9}
10public class Main {
11 public static void main(String[] args) {
12 User u = new User("Alex");
13 System.out.println(u.getName());
14 }
15}What is the output when accessing a static field shared across instances?
1class Counter {
2 static int count = 0;
3 public Counter() {
4 count++;
5 }
6}
7public class Main {
8 public static void main(String[] args) {
9 new Counter();
10 new Counter();
11 System.out.println(Counter.count);
12 }
13}What is the output when using an instance initializer and constructors?
1class Task {
2 private String name;
3 {
4 name = "Default";
5 }
6 public Task() {
7 }
8 public Task(String name) {
9 this.name = name;
10 }
11 public String getName() {
12 return name;
13 }
14}
15public class Main {
16 public static void main(String[] args) {
17 Task t = new Task("Email");
18 System.out.println(t.getName());
19 }
20}What is the output when using a record to model an immutable point?
1public record Point(int x, int y) {}
2public class Main {
3 public static void main(String[] args) {
4 Point p = new Point(3, 4);
5 System.out.println(p.x() + "," + p.y());
6 }
7}What is the output when using an anonymous class to override behavior?
1interface Greeter {
2 String greet();
3}
4public class Main {
5 public static void main(String[] args) {
6 Greeter g = new Greeter() {
7 public String greet() {
8 return "Hi";
9 }
10 };
11 System.out.println(g.greet());
12 }
13}Match each OOP concept with its description
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Match each Java type feature with its key property
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Click the line where the anonymous class is created
Click on the line to select.
interface ClickHandler { void onClick();} public class Button { public void setClickHandler(ClickHandler handler) { handler.onClick(); } public static void main(String[] args) { Button button = new Button(); button.setClickHandler(new ClickHandler() { public void onClick() { System.out.println("Clicked"); } }); }}Click the line where a static initializer block is defined
Click on the line to select.
public class Config { public static final String APP_NAME; public static final int TIMEOUT; static { APP_NAME = "Demo"; TIMEOUT = 30; } public static void main(String[] args) { System.out.println(APP_NAME + ":" + TIMEOUT); }}