Johnny White

Greenhorn
+ Follow
since Sep 12, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Johnny White

Thanks for the response Warren, and I took care of that Dirk .

I'm still a bit confused though. My book says construction is a two step process...does this mean that a superclass is always initialized as well as a subclass? If I make a regular class, without the use of extends, is there still a constructor used for a superclass from the .object class that is the class from which everything was inherited?

Which I think this is what Ernest was trying to tell me.

I have run some test programs, and indeed I noticed that the superclass is always instantiated as well as the subclass that I am constructing. However, how would I ever get in contact with this superclass?

My theory was that the superclass had to be constructed in order for the subclass to use it's variables and methods properly, but I instantiated a superclass with all of it's values at 0, and checked the subclass who I had given real numbers to, and they were different.

So to summarize my questions, is there an actual way to ever get in touch with the superclass? And is construction always a two step process in the sense that a superclass and a subclass are always constructed, even when not using extends?

Thanks guys. It's nice to have someone to ask the idiosyncrasies of the language to, because my teacher just looked at me like I had three heads and told me to not worry about it.
19 years ago
Thanks for the reply Ernest.

What is the actual point of having to construct an object of the superclass? I have all the methods I want in the subclass since they were inherited, and the variables as well..why instantiate another object in the superclass?

Would it be wise to just make a default empty constructor in the superclass everytime, and let the implicit super() construction that entails me not explicitly using a constructor for the superclass take over?

for example:

And then when I use extends


Or is the only point of this to be able to reuse the constructor and save you from typing out the initializations again, since that's basically what I just did.

Sorry for such a specific and trivial question, but I not only want to know how it works but why it works. Could you also please expound a bit more on your previous response, because I'm still a bit confused.

Every constructor, as the very first statement in its body, calls either another constructor from the same class, or a constructor from the superclass (the sole exception to this rule is the constructor java.lang.Object.Object(), which has no superclass constructor to call.)



Do you mean that every time I instantiate an object, the constructor in that object, calls the constructor in the class (which is the same constructor) ?

When you mention superclass, does this mean that even if I make one class, it still calls a constructor from the java.lang.Object class?

Thanks for the help man, I just want to be crystal clear on this.
19 years ago
Well first of all, I'd like to comment on what a great board and site this seems to be. Everyone seems very helpful and the information is well organized. Not just asskissing, I mean it.

Now onto my question.

I am trying to extend a class called Polygon:



With a class Triangle:



But I get an error: java:5: Polygon(int,int,int,int) in Polygon cannot be applied to ()

Which makes no sense to me since I thought the constructors were not passed on during inheritance.

I also noticed that the error disappears if I remove the Polygon constructor.

Can anyone explain why this is happening? I am playing around with it, but I don't understand the reason.

Thanks in advance.
19 years ago