class Parent {
private void display() {
System.out.println("Parent display()");
}
}
class Child extends Parent {
// This is NOT an override, just a new method in Child
private void display() {
System.out.println("Child display()");
}
}
default
and static
methods, enabling flexible code reuse without the risks of class-level multiple inheritance.
final
, finally
, and finalize()
?final
— applied to variables (makes them constants), methods (prevents overriding), and classes (prevents inheritance).finally
— a block used in exception handling that always executes, typically for cleanup.finalize()
— a method called by the garbage collector before reclaiming an object. Deprecated in Java 9 and removed in Java 18; developers should use try-with-resources
or Cleaner
API instead.java.util.Collections
).System.out.println()
, what do System
, out
, and println()
represent?System
— a final class in java.lang
providing system-level utilities.out
— a static field of type PrintStream
within System
, representing the standard output stream.println()
— a method of PrintStream
that prints text and moves to a new line.default
methods with implementations and static
methods.
From Java 9 onward, they can also contain private
methods to share common code internally.
java.util.Calendar
provides the static getInstance()
method that returns a concrete subclass instance.
x < y ? a : b = p * q
?result = (x < y) ? a : (p * q);
If x < y
evaluates to true
, a
is chosen; otherwise, p * q
is chosen.
Always check parentheses and operator precedence when using ternary expressions.
DOM (Document Object Model) | SAX (Simple API for XML) |
---|---|
Parses entire XML into a tree of objects. | Processes XML sequentially as events. |
High memory usage; suited for small to medium documents. | Low memory usage; suited for large documents. |
Slower for very large files due to full in-memory representation. | Faster for streaming and partial parsing. |
Easy navigation (random access supported). | No backward navigation; forward-only. |
Simpler to manipulate XML structure programmatically. | Requires custom code for building object structures. |