aspose file tools*
The moose likes Beginning Java and the fly likes The super keyword and packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "The super keyword and packages" Watch "The super keyword and packages" New topic
Author

The super keyword and packages

Olakunle Oladipo Oni
Greenhorn

Joined: Aug 28, 2008
Posts: 18
(1) I asked a question concerning the super keyword a week earlier but answer was not satisfactory. One of the reasons i guess was the way the question was presented. I'll be as clear as i can be at the moment and i'll appreciate someone's patience in giving me a detailed answer (as can be possible) to the question that will be raised. 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:


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? 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.

(2) I'm aware that packages a namespace implementation mechanism to prevent clashes with class names. I'm also aware that package names map to directory path. I want in a concise explanation with a reality scenario as a reference point how a name clash from classes of different packages may occur. Assuming I've created classes/interfaces in package myfiles.ex.yz which map to myfiles\ex\yz folder path on my computer (the classes/interfaces are actually available in the yz folder). How do i make this package available to another programmer via the web? Must the folder structure be published as it is? How can another programmer access my package on his computer. I'm appreciate a practical answer. Will a programmer download a path of folders and what directory will be ideal to place this directory path. My default directory (where my jdk utilities reside) follows the following path c:\Program Files\Java\jdk1.6.0_24\bin and it is in this same directory that i have the \myfiles folder that start my package structure. Recently i wanted to run an applet demo( that came with the jdk) from this directory path using the command prompt: C:\Program Files\Java\jdk1.6.0_24\demo\applets\TicTacToe The appletViewer command did not work. I need clarity on how to set environment variable for paths on my system through the advanced settings tab. One final question, where can i actually locate the standard and extended java class library (That's usually imported)
on the file system of my computer?

Olakunle Oladipo Oni
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19004
    
  40

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)
{
super(a,b);

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?



Parameters to the constructor are just like parameters to a method -- they are essentially local to the constructor (just like local variables). And the constructor calling the super() constructor is similar to a method call another method -- it is passing a variable, which happens to be a local variable, to another method. There is nothing specific to inheritence, in regards to parameter handing -- standard parameter passing rules apply.

And there is no "derived class contructor declaring its own version (copy) of the ...", etc. This are like local variable -- not instance or class variables.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19004
    
  40

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.


And I guess the rest of you questions regarding this are also moot.... as again, these are local variables, and not class or instance variables.

Henry
Olakunle Oladipo Oni
Greenhorn

Joined: Aug 28, 2008
Posts: 18
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
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39885
    
  28
The whole process is described in the Java Language Specification. Read that . . . slowly; it is not easy to read.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19004
    
  40

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



Also, perhaps you can elaborate your question? Or maybe provide an example? I don't seem to completely follow what you are asking.

Henry
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39885
    
  28
This recent thread has an example of collisions of similarly named classes.
When I was doing my MSc somebody (who was also on JavaRanch) imported java.util.* and javax.swing.* and had collision problems with the Timer class.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The super keyword and packages