NOTE
OOP
Inheritance affects constructors, fields, and methods in Java. These notes examine those relationships through parent-child class examples.
This is a historical learning note and may contain outdated or incomplete understanding.
1. When Creating a Subclass Object, Is a Parent-Class Object Also Created?
No.
The super keyword simply calls the parent-class constructor to initialize fields.
2. Does a Subclass Inherit the Parent Class’s Private Variables?
In terms of inheritance, private and final are not inherited. This is how the official Java documentation describes it.
From the memory perspective, everything in the parent class is inherited (this can be seen from the parent constructor being called: when an object is created with new, the constructor is called; when a subclass is created, the parent constructor is called. Therefore, from the memory perspective, the subclass contains a complete parent-class portion).
3. References
Drag to pan, scroll to zoom, and click a node to expand or collapse it. Large maps start with deeper levels collapsed; click nodes to expand them.
Discussion
Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub