Heres an example of what I mean:
public class Rectangle
{
private int length;
private int breadth;
.
.
}
public class Box extends Rectangle
{
private int height;
.
.
}
When you:
Box b = new Box();
Does it create a Box as well as a Rectangle object, with the rectangle not directly accessible, but only accessible through the Box object. In other words, does it create two objects in memory?
No, it creates a single object. This single object represents a
Box(and since this is a subtype ofRectanglethis same object represents aRectangleas well).The inheritance simply ensures that the interface of the
Boxobject is an extension of theRectangleinterface.