Olakunle Oladipo Oni wrote:(I'm aware that the super keyword is a way for the superclass part (the superclass constructor) of
a derived class to be initialized. So it is the first required statement after the constructor declaration of the derived class. This idiom takes the typical form:
public Myderived(int a, int b, double c)
area = c;
Now i'll make some propositions/analysis concerning the above code snippet in the light of my present understanding and raise my questions as well. If anything sounds invalid from my propositions/analysis i'll appreciate a corrective response as addition to the given answers. Firstly according to the code the parameters 'int a and int b' became a part of the derived class contructor by virtue of inheritance and access control of the superclass. Is the derived class contructor declaring its own version (copy) of the instance variables (from the superclass) or simply referencing what's already present in the superclass? If the variables had a 'private' access control in the superclass can they still be declared/referenced in the derived class constructor even if the derived class doesn't have access to them?
Olakunle Oladipo Oni wrote: My understanding of the super keyword is as a means of initializing the superclass contructor. Is it really the superclass intializing itself or the subclass doing the initialization since the value passed when the subclass contructor is called is passed to the superclass constructor via super(a,b);? If the value passed as arguments to the subclass constructor is transferred to the superclass constructor via super(a,b); i.e. (If this is correct) Then the subclass and superclass should have the same values for these variables . What if i want the same variables to typically be initialized differently for the superclass and the subclass? The crux of all the questions is that if the my my superclass gets initialized by calling super(a,b); is the subclass sharing the initialization or does it really need to have its own initialization for the same set of variables?. I'll appreciate a clear cut answer.
Olakunle Oladipo Oni wrote:Mr Wong
In response to the reply of my topic "super keyword and packages" which you gave on the 08, April 2012, I would say i appreciate the reply. I would have appreciated more people baring their mind on the question and this hopefully
could have supplied more answers. There are some parts of my question which your answer didn't address. One thing i wanted to get clearly was if the subclass gets initialized with different values (for the instance variables) from that
of the superclass by calling super(a,b); assuming access level of these two variables from the superclass isn't private. Though the parameters supplied in the subclass constructor is local to the constructor, is that enough to initialize
the variables differently from that of the superclass or does the value supplied by calling the subclass constructor become that of the superclass as well? I wouldn't want you to mind my seemingly over flogging the topic but try give me
a comprehensive answer. Since you are the only one who gave answer to this topic, i deem it fit to send you this reply. Hoping to hear from you.
olakunle oladipo oni