Article View: borland.public.jbuilder.java.language
Article #14Re: Extending custom classes
From: John P. McGrath
Date: Mon, 19 Oct 1998 00:00
Date: Mon, 19 Oct 1998 00:00
41 lines
2247 bytes
2247 bytes
Vladimir Olenin <keenonjava@collegemail.com> wrote: > i have a class A that extends Thread. Then, i have class B > that extends A. The first problem was that i didn't compile > printing out the error that "class A doesn't have A() > constructor" To tell the truth it really hadn't have such. > When i added an empty one, this error disappeared. Since B is a subclass of A, each constructor for B must either call a constructor for A, or another constructor for B (which must eventually call an A constructor). If you do not specify a constructor call in the B constructor, such as one of the following: super(...); // Calls the superclass constructor this(...); // Calls another B constructor then the compiler will generate a call to the superclass constructor with no arguments. So the compiler is generating a call to A() in one of your B constructors. If you do not specify any constructors in a class, then the compiler will automatically generate one for you. In other words, if you did not define any constructors for A, it would have generated the A() constructor that is missing. But since you did define an A constructor with arguments, it does not do this. > So, the question is can i do this (call A constructor > from try catch blok) or not? No. The first thing done in a constructor must always be to call the superclass constructor. And calling a constructor from any other location is not allowed. -- Regards, John P. McGrath <mcgrath@enter.net> <jpm@nscs.fast.net>
Technical Details
Message-ID:
<MPG.1094ccab7ba0cda99896e3@forums.inprise.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<3627D405.39785DA8@collegemail.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,d081ad3c3fbcd4c7 X-Google-Attributes: gid111d45,public X-Google-Thread: ff01d,d081ad3c3fbcd4c7 X-Google-Attributes: gidff01d,public X-Google-Thread: f74b3,d081ad3c3fbcd4c7 X-Google-Attributes: gidf74b3,public From: mcgrath@enter.net (John P. McGrath) Subject: Re: Extending custom classes Date: 1998/10/19 Message-ID: <MPG.1094ccab7ba0cda99896e3@forums.inprise.com> X-Deja-AN: 402747016 References: <3627D405.39785DA8@collegemail.com> Organization: Software Consulting Services Newsgroups: borland.public.jbuilder.java.language,borland.public.jbuilder.java.swing,borland.public.jbuilder.applet-issues