Chapter 7: Beyond Classes Flashcards

1
Q

Anonymous classes can be declared static?

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Anonymous classes always have an implicit reference to their enclosing class?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Anonymous classes are a type of nested class that can be static?

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Since anonymous classes cannot be static, they must be associated with an instance of the enclosing class?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The keyword “static” can be used when defining anonymous classes?

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Interface variables in Java are public, static, and final by default.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Interfaces in Java are required to define at least one method.

A

False: Interfaces can be empty, and the compiler automatically treats them as abstract even without method definitions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

An interface can be instantiated directly

A

False: Interfaces cannot be instantiated because they only provide method signatures without implementations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Interfaces are implicitly considered abstract, even without the abstract keyword.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Interfaces can be marked as final in Java.

A

False: Interfaces cannot be final, as final would prevent implementation, defeating their purpose.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

In Java 17, if a class inherits two interfaces with the same default method signature, it must override the method. (True/False) If false, why?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

A class can inherit conflicting default methods from multiple interfaces without requiring an override. (True/False) If false, why?

A

False – The compiler enforces overriding to resolve ambiguity in method implementation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

The syntax to access an inherited default method is <interface>.super.<method>. (True/False) If false, why?</method></interface>

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

In Java 17, a class can directly call a default method from an interface without specifying the interface name. (True/False) If false, why?

A

False – It must use <interface>.super.<method> to specify the source interface.</method></interface>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Default methods in interfaces cannot be overridden by implementing classes. (True/False) If false, why?

A

False – Implementing classes can override default methods to provide custom behavior.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

An interface can extend multiple interfaces using the extends keyword.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

A class can extend multiple interfaces.

A

False – A class implements interfaces, but it can extend only one class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Interfaces are initialized as part of a class hierarchy.

A

False – Interfaces do not have constructors and are not part of instance initialization.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

A class can extend an interface.

A

False – A class can only implement an interface, not extend it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

An interface can implement another interface.

A

False – An interface can extend another interface, but it cannot implement one.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

A method that properly overrides inherited methods can use covariant return types.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Interfaces are implicitly abstract.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Interface variables are implicitly public, static, and final.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

If a method or variable is marked with a conflicting modifier, the compiler applies the public modifier without conflict.

A

The compiler detects a conflict and generates an error.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Both abstract classes and interfaces use implicit modifiers.

A

False – Only interfaces use implicit modifiers; abstract classes do not. If false, why?

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

A constant variable in an interface is implicitly public static final. If false, why?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

An abstract method in an interface is implicitly private abstract. If false, why?

A

False – It is implicitly public abstract.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

A default method in an interface must be marked with the default keyword and have a method body. If false, why?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

A static method in an interface is implicitly private static. If false, why?

A

False – It is implicitly public static.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

A private method in an interface can have an abstract modifier. If false, why?

A

False – Private methods must have a method body, so they cannot be abstract.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

A private static method in an interface does not require a method body. If false, why?

A

False – All private methods must have a method body.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

A method marked protected in an interface is allowed. If false, why?

A

False – Interfaces do not support protected methods because they cannot be extended like classes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

A method in an interface without an access modifier is implicitly package-private. If false, why?

A

False – It is implicitly public, to maintain backward compatibility.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

A default method in an interface can be marked final. If false, why?

A

False – Default methods cannot be final because they are meant to be overridden.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

A class must override a default method if it inherits two default methods with the same signature. If false, why?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

A class implementing an interface must override all its default methods. If false, why?

A

False – Default methods are optional to override; they have a provided implementation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

An interface can contain both static and private methods. If false, why?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

A class implementing multiple interfaces with the same default method must override the method to resolve ambiguity. If false, why?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

A default method in an interface behaves only like an instance method, not like a static method. If false, why?

A

False – It exhibits properties of both static and instance methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

The super keyword is used with interface names to indicate following instance inheritance. If false, why?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

Interfaces can declare static methods without using the static keyword. If false, why?

A

False – A static method must be explicitly marked with static.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
42
Q

Static methods in interfaces are always private by default. If false, why?

A

False – They are implicitly public if no access modifier is provided.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
43
Q

Static methods in interfaces cannot be inherited by implementing classes. If false, why?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
44
Q

An interface can define a static method without a method body. If false, why?

A

False – A static method must always have a method body.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q

Static methods in interfaces can be marked as final. If false, why?

A

False – Static methods in interfaces cannot be final.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
46
Q

Private static interface methods can be called by any method within the interface. If false, why?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
47
Q

A private non-static interface method can be called by both static and non-static methods within the interface. If false, why?

A

False – It can only be called by non-static methods.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
48
Q

Private interface methods were introduced primarily to enhance encapsulation and reduce code duplication. If false, why?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
49
Q

A private interface method can be called directly from a class implementing the interface. If false, why?

A

False – Private methods in interfaces cannot be accessed by implementing classes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
50
Q

A class can override a private method of an interface. If false, why?

A

False – Private methods in interfaces are not inherited, so they cannot be overridden.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
51
Q

An interface can have both default and static methods. If false, why?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
52
Q

A private interface method can be marked as abstract. If false, why?

A

False – Private methods must have a method body, so they cannot be abstract.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
53
Q

A private static interface method can be accessed by another private static method within the same interface. If false, why?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
54
Q

Default and private non-static methods in an interface can access abstract methods. If false, why?

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
55
Q

Abstract methods in an interface require an instance of the interface for access. If false, why?

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
56
Q

Constant variables in an interface can be accessed without an instance. If false, why?

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
57
Q

Private static methods in an interface are accessible from other static methods within the same interface. If false, why?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
58
Q

Default methods in an interface are accessible by classes implementing the interface. If false, why?

A

True.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
59
Q

Static methods in an interface require the interface name for access. If false, why?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
60
Q

Abstract methods in an interface are accessible within the interface itself. If false, why?

A

Abstract methods cannot have a body and are not accessible within the interface. (False)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
61
Q

Private methods in an interface are accessible from implementing classes. If false, why?

A

Private methods are only accessible within the interface itself. (False)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
62
Q

You can extend an enum to add more values. If false, why?

A

Enums are final by design and cannot be extended. (False)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
63
Q

Enum values can be dynamically modified at runtime. If false, why?

A

Enum values are constants and immutable. (False)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
64
Q

The semicolon at the end of a simple enum’s value list is required. If false, why? )

A

It is optional unless additional code follows. (False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
65
Q

Enums do not offer type safety compared to using constants. If false, why?

A

Enums are type-safe, unlike numeric or string constants. (False)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
66
Q

An enum provides a values() method to get an array of all of the values. You can use this like any normal array, including in a for-each loop.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
67
Q

Each enum value has a corresponding int value, and the values are listed in the order in which they are declared.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
68
Q

You can’t compare an int and an enum value directly since an enum is a type, like a Java class, and not a primitive int.

69
Q

The valueOf() method allows retrieving an enum value from a String, and the String must match the enum value exactly.

70
Q

Enums can be used in both switch statements and switch expressions.

71
Q

All enum constructors are implicitly private, and using public or protected in the constructor will result in a compilation error

72
Q

Enum values can be modified after they are created.

A

Enum values should be immutable since they are shared in the JVM, and modifying them is a poor practice.

73
Q

Enum constructors can be explicitly declared as public or protected.

A

Enum constructors are always private (implicitly or explicitly); public or protected modifiers cause a compilation error.

74
Q

Enums must contain only a list of values and cannot have instance variables or methods.

A

Enums can have instance variables and methods, making them more complex if needed.

75
Q

The order of enum values can be changed at runtime.

A

Enum values are assigned at compile-time and cannot be reordered at runtime.

76
Q

You can extend an enum in Java.

A

Enums are implicitly final, meaning they cannot be subclassed.

77
Q

In an enum, instance variables are shared across instances of the enum.

A

Each enum value is a singleton, so instance variables are specific to each enum constant.

78
Q

A sealed class is a class that restricts which other classes may directly extend it.

79
Q

A sealed class declares a list of classes that can extend it, while the subclasses declare that they extend the sealed class.

80
Q

Sealed classes are commonly declared with the abstract modifier, although this is certainly not required.

81
Q

Every class that directly extends a sealed class must specify exactly one of the following three modifiers: final, sealed, or non-sealed.

82
Q

Besides classes, interfaces can also be sealed, and many of the same rules apply.

83
Q

The permits keyword is mandatory when declaring a sealed class.

A

It is optional if all subclasses are in the same file or nested.

84
Q

A non-sealed class cannot be extended by other classes.

A

(A non-sealed class removes restrictions and allows unrestricted extension.)

85
Q

A sealed class can be extended by any class in the same package.

A

(Only explicitly permitted subclasses can extend a sealed class.)

86
Q

Sealed interfaces must have their permitted classes/interfaces listed using permits.

A

(The permits clause is optional in certain conditions.)

87
Q

The permits clause must always explicitly list all allowed subclasses.

A

(It can be omitted if subclasses are declared in the same file or are nested.)

88
Q

A final interface can extend a sealed interface.

A

(Interfaces cannot be marked final; they can only be sealed or non-sealed.)

89
Q

Sealed interfaces and their implementations must be in different packages.

A

(They must be in the same package or module.)

90
Q

A sealed class and its permitted subclasses must be in different files.

A

(They can be in the same file or even be nested.)

91
Q

The permits clause must always be used for nested subclasses.

A

(It can be omitted if all subclasses are declared within the same sealed class.)

92
Q

Sealed classes are declared with the sealed and permits modifiers.

93
Q

Sealed classes must always be declared in a named module along with their direct subclasse

A

They must be in the same package or module, but not necessarily a named module

94
Q

Direct subclasses of a sealed class can be marked as abstract.

A

(False – They must be marked final, sealed, or non-sealed.)

95
Q

The permits clause is optional if the sealed class and its direct subclasses are in the same file.

96
Q

A sealed interface can only limit the classes that implement it, not the interfaces that extend it.

A

(False – It can limit both implementing classes and extending interfaces.)

97
Q

A POJO requires a no-arg constructor like a JavaBean.

A

(False – A POJO does not require a no-arg constructor.)

98
Q

Encapsulation prevents modifying methods in a class.

A

(False – Encapsulation restricts direct access to instance variables but allows method modifications.)

99
Q

Encapsulation ensures that method behavior cannot change in the future.

A

(False – Methods can be modified while maintaining the same signatures.)

100
Q

Records allow defining explicit setter methods.

A

(False – Record fields are implicitly final, so setters are not allowed.)

101
Q

The constructor of a record allows parameters in any order.

A

(False – It follows the same order as the record declaration.)

102
Q

The equals() method of a record allows customization without overriding it.

A

(False – Customization requires explicitly overriding equals().)

103
Q

Records automatically generate a toString() method that includes all fields.

104
Q

The final modifier prevents a class from being extended.

105
Q

Java allows a class to have multiple direct parent classes.

A

(False – Java supports single inheritance, but a class can implement multiple interfaces.)

106
Q

A class in Java can extend multiple classes at the same time.

A

(False – Java does not allow multiple inheritance for classes.)

107
Q

Abstract classes are an exception to Java’s single inheritance rule.

A

(False – Java’s exception to single inheritance is interfaces, not abstract classes.)

108
Q

A subclass in Java can inherit directly from two different superclasses.

A

(False – A subclass can have only one direct parent class.)

109
Q

If a class has a parent, it cannot have multiple child classes.

A

(False – Single inheritance does not prevent a parent class from having multiple children.)

110
Q

All Java classes implicitly inherit from java.lang.Object.

111
Q

Primitive types like int and boolean inherit from Object.

A

(False – Primitive types are not classes and do not inherit from Object.)

112
Q

If a class extends another, Java implicitly adds extends Object.

A

(False – Java does not implicitly extend Object if a class already extends another.)

113
Q

If a class has no explicit superclass, Java automatically extends java.lang.Object.

114
Q

The equals() method in Java is always useful for comparing objects.

A

(False – The equals() method must be overridden for meaningful comparisons.)

115
Q

By default, toString() in Java provides a human-readable description of an object.

A

(False – The default toString() returns a memory reference unless overridden.)

116
Q

Java allows a class to extend multiple classes using the extends keyword.

A

(False – A class can extend only one class but implement multiple interfaces.)

117
Q

The inheritance structure of every Java class ends with null.

A

(False – The inheritance structure always ends with Object, not null.)

118
Q

Java automatically calls super.toString() when printing an object.

A

(False – super.toString() is not automatically called unless explicitly implemented.)

119
Q

Object is the only class in Java that does not have a parent.

120
Q

All permitted subtypes of a sealed type must belong to the same package.

A

False – They can belong to the same package or the same named module.

121
Q

A sealed class in a named module can have permitted subtypes from different modules.

A

False – All permitted subtypes must belong to the same module as the sealed class.

122
Q

If a sealed class is in an unnamed module, all its permitted subtypes must be in the same package.

A

✅ True – This is required to avoid a compile-time error.

123
Q

A sealed class in a named module can permit subtypes from different packages as long as they are in the same module.

A

✅ True – The package restriction applies only to unnamed modules.

124
Q

A permitted subclass of a sealed class must always be in the same package.

A

❌ False – This is only true for unnamed modules. For named modules, the permitted subclass can be in a different package as long as it is in the same module.

125
Q

The permits clause of a sealed class is optional if all permitted subclasses are declared in the same file.

A

✅ True – If all subclasses are declared in the same compilation unit, Java can infer the permitted subclasses.

126
Q

If a sealed class is declared in an unnamed module, it can permit subclasses from different modules.

A

❌ False – Unnamed modules don’t allow cross-module subclassing.

127
Q

If a sealed class does not specify permits, it becomes non-sealed automatically.

A

❌ False – It only means Java will infer the permitted subclasses from the same compilation unit.

128
Q

A sealed class in a named module can only have subclasses that are also in named modules.

A

✅ True – The subclasses must be in the same named module.

129
Q

If a sealed class and its permitted subclasses are in different named modules, Java will generate a compile-time error.

A

✅ True – A named module cannot have permitted subclasses in another module.

130
Q

Records don’t have setters because every field is inherently final and cannot be modified after construction.

A

(✅ True)

131
Q

Records are implicitly final, meaning they cannot be extended.

A

(✅ True)

132
Q

A record can implement a regular or sealed interface if it implements all the abstract methods.

A

(✅ True)

133
Q

Records promote immutability, making them inherently thread-safe and suitable for concurrent frameworks.

A

(✅ True)

134
Q

If a record has a constructor with the same parameter list as the automatically generated one, the compiler does not insert its own constructor.

A

(✅ True)

135
Q

Records allow fields to be modified after object creation.

A

(❌ False – Fields in records are final.)

136
Q

Records must explicitly declare the final keyword to prevent extension.

A

(❌ False – They are implicitly final.)

137
Q

Records can extend other records or classes like normal Java classes.

A

(❌ False – They cannot extend any class.)

138
Q

Records cannot have constructors with validation logic.

A

(❌ False – They can include validation logic, as shown in the example.)

139
Q

Records eliminate all boilerplate code, even when declaring custom constructors.

A

(❌ False – Declaring a constructor with many fields still introduces boilerplate code.)

140
Q

True/False: A Java record automatically provides a canonical constructor if no constructor is explicitly declared.

A

True – If no constructor is defined, Java generates a default canonical constructor.

141
Q

A compact constructor in a record must explicitly declare parameter names.

A

Compact constructors omit explicit parameter declarations; the parameters are inferred from the record components.

142
Q

A record in Java can have multiple compact constructors.

A

False – A record can have only one compact constructor

143
Q

A compact constructor in a record allows performing validation or transformation of input parameters before assigning values to fields.

A

True – Compact constructors enable adding logic like validation before record fields are assigned.

144
Q

If a record has a compact constructor, the compiler still generates a default canonical constructor separately.

A

The compact constructor replaces the canonical constructor; the compiler does not generate an additional one.

145
Q

The compact constructor in a record does not require explicit assignment of values to record fields.

A

True – Java automatically assigns values to record components in a compact constructor.

146
Q

A record in Java cannot have additional instance fields beyond the components defined in its declaration.

A

True – Records only store the fields defined in the record header; no extra instance fields are allowed.

147
Q

The canonical constructor in a record must always call super() explicitly.

A

False – The compiler automatically inserts super() where necessary, so it is not required to be explicitly called.

148
Q

A record constructor can define extra fields not listed in the record header.

A

False – Records cannot define additional instance fields beyond those in the record header.

149
Q

The primary purpose of a compact constructor in a record is to simplify code by allowing logic such as validation without explicitly listing parameters.

A

True – Compact constructors help keep code clean by allowing logic like validation without requiring explicit parameter declarations.

150
Q

A record in Java can have overloaded constructors that take a completely different list of parameters.

151
Q

A static nested class is a static type defined at the member level of a class.

152
Q

Compact constructors in a record are declared without curly braces {} to distinguish them from normal constructors.

A

❌ (Compact constructors require curly braces like normal constructors.)

153
Q

A compact constructor in a record can modify both constructor parameters and instance fields.

A

❌ (Compact constructors can modify parameters but not instance fields.)

154
Q

Instance initializers are supported in records to allow additional initialization logic outside constructors.

A

❌ (Records do not support instance initializers; all initialization must be done in a constructor.)

155
Q

A record can define additional instance fields outside the record declaration as long as they are private.

A

❌ (Records do not allow extra instance fields outside the declared components.)

156
Q

Anonymous classes are a special case of nested classes that are always static.

A

❌ (Anonymous classes are always inner classes and cannot be static.)

157
Q

Overloaded constructors in a record must always call the primary constructor using this().

A

❌ (Overloaded constructors do not have to call the primary constructor.)

158
Q

A local class is defined at the member level of a class, similar to inner and static nested classes.

A

❌ (Local classes are defined within a method body, not at the member level.)

159
Q

A nested class in Java can only be a static nested class or an inner class, with no other variations.

A

❌ (There are four types: inner class, static nested class, local class, and anonymous class.)

160
Q

The Java compiler will execute the full constructor of a record after executing the compact constructor.

A

❌ (The compact constructor is the full constructor; there is no separate execution.)

161
Q

What does the sealed keyword do in a Java class declaration?

A

A sealed class restricts which classes can directly extend or implement it. These permitted subclasses must be explicitly listed using the permits keyword, and each must be declared as final, sealed, or non-sealed

162
Q

What does the non-sealed modifier mean when applied to a subclass of a sealed class?

A

A non-sealed subclass of a sealed class allows further extension by unspecified classes. This essentially reopens the inheritance hierarchy beyond the explicitly permitted list in the sealed class​

163
Q

What must be true for all direct subclasses of a sealed class?

A

All direct subclasses of a sealed class must be in the same package or named module and must be explicitly marked as final, sealed, or non-sealed. If they are in the same file or are nested, the permits clause can be omitted

164
Q

What is the main syntactic difference between a canonical and a compact constructor in Java records?

A

The canonical constructor explicitly declares parameters and assigns fields, while the compact constructor omits the parameter list and assigns fields implicitly.

165
Q

When should you use a compact constructor in a Java record?

A

Use a compact constructor when the constructor parameters match the record components and you only need to add simple validation or transformation logic.

166
Q

Which type of constructor allows you to rename parameters or use completely custom logic?

A

The canonical constructor — it provides full control over parameters, naming, assignments, and logic.

167
Q

Can an abstract class be sealed in Java?

A

Yes. An abstract class can be declared sealed to restrict which classes are allowed to extend it.

168
Q

What must all subclasses of a sealed abstract class declare?

A

They must be explicitly marked as either final, sealed, or non-sealed.

169
Q

Why use a sealed abstract class instead of a regular one?

A

To control the inheritance hierarchy while still requiring subclasses to implement behavior, often enabling exhaustiveness in pattern matching and safer design.