You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: oop.md
+147-1Lines changed: 147 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -499,4 +499,150 @@ class Implementation implements A, B {
499
499
**💡 Learning Tip:** Think "INTERFACE = CONTRACT" - defines what must be done (public methods) but allows flexibility in how (default methods provide optional behavior).
500
500
501
501
**Q:** What happens if a class implements two interfaces with conflicting default methods?
502
-
**A:** Compile error — the class must override the conflicting method to explicitly resolve which implementation to use or provide its own.
502
+
**A:** Compile error — the class must override the conflicting method to explicitly resolve which implementation to use or provide its own.
503
+
504
+
## 🃏Nested Classes vs Inner Classes - Key Distinctions
505
+
506
+
**Rule:** Inner class = NON-STATIC nested class. All inner classes are nested, but not all nested classes are inner.
507
+
508
+
**Class Classification Hierarchy:**
509
+
***Top-level class** → Not nested (declared at package level)
510
+
***Nested class** → Declared inside another class/interface body
// Pitfall 4: Static nested accessing instance members
635
+
classExample {
636
+
String field ="test";
637
+
staticclassBadNested {
638
+
voidmethod() {
639
+
// System.out.println(field); // ❌ Cannot access instance field
640
+
}
641
+
}
642
+
}
643
+
```
644
+
645
+
**💡 Learning Tip:** "Static nested = NO instance access, Inner = FULL access" - Static nested classes can't access instance members, while inner classes can access everything in the outer class.
646
+
647
+
**Q:** What's the key difference between a static nested class and an inner class?
648
+
**A:** A static nested class cannot access non-static members of the outer class and doesn't need an outer instance to be created, while an inner class (non-static nested) can access all outer class members and requires an outer instance.
0 commit comments