|
March 29, 2001 Protecting Private Data Elements Tips: March 2001
Yehuda Shiran, Ph.D.
|
|
Each subclass can change private data types permanently, affecting the values seen by all other subclasses. One way to overcome this problem is to call the superclass constructor from within each subclass constructor. In this way, each subclass creates a local copy of the private data members, and does not step over its peer subclasses memory.
There are two ways to call a constructor from within a constructor. One way is to use the
After we define
Try it. The second way to call a constructor from within a constructor is by defining the superclass constructor as a method of the subclass constructor. Here is the superclass
After we define
People who read this tip also read these tips: Look for similar tips by subject: |