Inheritance in Java
Inheritance lets a subclass acquire the members of a superclass, creating an is-a relationship that polymorphism is built on.
Core Java, object oriented programming, collections, multithreading and JDBC.
100 notes in 18 topics
Inheritance lets a subclass acquire the members of a superclass, creating an is-a relationship that polymorphism is built on.
A subclass replaces inherited behaviour by declaring the same signature, and the JVM chooses the version at runtime from the actual object.
One reference type, many possible behaviours. Polymorphism is what lets code work with a supertype and stay correct as new subtypes appear.
Abstraction exposes what a type does and hides how. Abstract classes share partial implementation, interfaces declare a capability.
Most relationships between classes are has-a, not is-a. Composition is usually the more flexible and more honest design.
From new to unreachable: how objects are created, how long they live, and what actually happens when nothing references them any more.
Every class inherits from Object, which is where toString, equals, hashCode and getClass come from.
Two objects that are equal must have the same hash code. Breaking that contract quietly breaks every hash based collection.
final means cannot be reassigned, cannot be overridden or cannot be extended, depending on where it is written.
instanceof tests the runtime type, and since Java 16 it can bind a typed variable in the same step.
Packages give classes a unique name and a visibility boundary, and imports simply save you from writing that full name every time.
A class declared inside another can be static, inner, local or anonymous, and the difference is mainly what each one can see.