Last Updated: January 3, 2026
31 quizzes
Access the current object's instance field inside the constructor of the Product class
this.name = productName;Click an option to fill the blank:
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?
Which keyword lets a static nested class access only static members of its outer class directly?
What is a key characteristic of a record class in Java?
In a sealed class hierarchy, what must each direct subclass be declared as?
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.
Order the steps to create and use a sealed Shape hierarchy with two final implementations
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}Find the bug related to access modifiers in this code
Click on the line(s) that contain the bug.
public class Account { public double balance; public void deposit(double amount) { balance += amount; } public double getBalance() { return balance; }}Find the bug involving static and instance members in this code
Click on the line(s) that contain the bug.
public class Session { private static String userName; public Session(String userName) { this.userName = userName; } public String getUserName() { return userName; }}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.
Complete the code so the Person class is immutable and exposes its data safely
public final class Person { private final String name; public Person(String name) { this.name = name; } public () { return name; }}Click an option to fill blank 1:
Complete the sealed hierarchy so only specific shapes are allowed
public sealed abstract class Shape Circle, Rectangle { public abstract double area();}public final class Circle extends Shape { private final double radius; public Circle(double radius) { this.radius = radius; } public double area() { return Math.PI * radius * radius; }}public final class Rectangle extends Shape { private final double width; private final double height; public Rectangle(double width, double height) { this.width = width; this.height = height; } public double area() { return width * height; }}Click an option to fill blank 1:
Complete the record declaration to model an immutable 2D size
public Size(int , int ) {}Click an option to fill blank 1:
Complete the inner class code so it can access the private field of the outer class
public class Order { private int id; public Order(int id) { this.id = id; } public class { public String format() { return "Order-" + .id; } }}Click an option to fill blank 1:
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); }}