Using final with inheritance

Using final with inheritance The keyword final has three Uses. First, it can be used to create the equivalent of a  .named constant. This use was described in the preceding chapter. The other two uses  of final apply to inheritance. Both are examined here Using final...

Applying Method Overriding

Applying Method Overriding Let’s look at a more practical example that uses method overriding. The following  program creates a super class called Figure that stores the dimensions of various two-dimensional objects. It also defines a method called area that...

When Constructors are Called

When Constructors are Called When a class hierarchy is created, in what order are the constructors for the classes that, make up the called ?For example, given a subclass called B and a super class called A, is. As constructor called before B’s, or vice The...

Creating a Muiti level Hierarchy

Creating a Mufti level Hierarchy Up to this point, we have been using simple class hierarchies that consist of only a super class and a subclass. However, you can build hierarchies that contain as many layers of inheritance as you like. As mentioned, it is perfectly...

A Super class Variable Can Reference a Subclass

A Super class Variable Can Reference a Subclass  A reference variable of a super class can be assigned a reference to any subclass derived from that super class. You will find this aspect of inheritance quite useful in a variety of situations. For example, consider...

Member Access and Inheritance

Member Access and Inheritance Although a subclass includes all of the members of its super class, it cannot access those members of the super class that have been declared as private. For example, consider the following simple class hierarchy. This program will not...