🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #8054

Re: beginning java: constructor problem with subclass

#8054
From: hi
Date: Sun, 22 Apr 2001 07:58
86 lines
3517 bytes
Hi,

Thanks for the response.  I guess I don't understand what the constructor
for the class TestPrivate2 has anything to do with me trying to create a
TestPrivate1a object.

Ohhh...now I think I understand.  The error is not related to my trying to
create a TestPrivate1a object is it?  It is an error related to the compiler
creating a default constructor for the subclass, which by convention calls a
no argument constructor for the parent class, which does not exist and is
not supplied by the compiler because I have defined a constructor for the
parent class.  Is that it?  I would still get the error if I tried to create
an object from a totally unrelated class too, wouldn't I?


"Torsten Welches" <torsten.welches@who.cares.netcologne.de> wrote in message
news:3ae28b34_2@dnews...
> the error is due to the fact that the compiler add a default constructor
if
> (and only if) you haven't defined any constructors yourself. TestPrivate2
> has no constructor, so the compiler does his job and adds the following
code
> (behind the curtain)
>
> public TestPrivate2 {
>     super();
> }
>
> Recall that the very first statement of *every* constructor (except
> Object's) is always a call to a parent constructor (or an overloaded
> constructor) - if you don't do it yourself, the compiler assumes
"super();"
> for you.
>
> You now can easily see why the compiler is complaining, TestPrivate1a has
no
> matching constructor for (no args).
> You would either need to add a no-args constructor to TestPrivate1a or
write
> TestPrivate2 default constructor so that it properly calls TestPrivate1a's
> sole constructor, e.g.
>
> public TestPrivate2 {
>     super(0);
> }
>
> Torsten
>
> hi schrieb in Nachricht <3ae27b56$1_1@dnews>...
> >Hi,
> >
> >I am using some simple classes to test the different access specifiers,
but
> >I am getting the following error when I try to compile a subclass:
> >
> >TestPrivate2.java:1: cannot resolve symbol
> >symbol  : constructor TestPrivate1a  ()
> >location: class TestPrivate1a
> >public class TestPrivate2 extends TestPrivate1a
> >            ^
> >1 error
> >
> >
> >Here are my classes:
> >
> >public class TestPrivate1a
> >{
> > protected int iAmPro;
> > public TestPrivate1a(int x)
> > {
> >  iAmPro = x;
> > }
> >}
> >
> >public class TestPrivate2 extends TestPrivate1a
> >{
> > public static void main(String[] args)
> > {
> >  TestPrivate1a   aTestPrivate1a = new TestPrivate1a(10);
> >  System.out.println(aTestPrivate1a.iAmPro);
> > }
> >}
> >
> >
>
>
Technical Details
Message-ID: <3ae28f68_2@dnews>
Path: arc1-ca.pugleaf.net!newsfeed.google.com!sn-xit-03!supernews.com!news-xfer.nuri.net!newspump.monmouth.com!newspeer.monmouth.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnews
References: <3ae27b56$1_1@dnews> <3ae28b34_2@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,69cce75b48e20b78
X-Google-Attributes: gidf74b3,public
X-Google-ArrivalTime: 2001-04-22 01:14:03 PST
From: "hi" <noneofyourbusiness@none.com>
Newsgroups: borland.public.jbuilder.java.language
References: <3ae27b56$1_1@dnews> <3ae28b34_2@dnews>
Subject: Re: beginning java: constructor problem with subclass
Date: Sun, 22 Apr 2001 01:58:44 -0600
Lines: 88
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
NNTP-Posting-Host: 208.187.113.66
Message-ID: <3ae28f68_2@dnews>
X-Trace: dnews 987926376 208.187.113.66 (22 Apr 2001 00:59:36 -0700)
Path: arc1-ca.pugleaf.net!newsfeed.google.com!sn-xit-03!supernews.com!news-xfer.nuri.net!newspump.monmouth.com!newspeer.monmouth.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnews