This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes superclass' default construct Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "superclass Watch "superclass New topic

superclass' default construct

Roger Zhao
Ranch Hand

Joined: Aug 05, 2003
Posts: 73
Hi, all:

The default constructor(no arguments) in Class B is needed to compile the constructor marked **. why?
Added code tags - Barry
[ August 18, 2003: Message edited by: Barry Gaunt ]

"There is a will,there is a way!"<br />SCJP1.4
Carl Trusiak

Joined: Jun 13, 2000
Posts: 3340
Any subclass Constructor that does not have an explicate call to it's Super class Constructor gets an implicate call to the super classes default constructor. The code:

is exactly the same as

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Is class A extending Demo or B?
If it's B, then, as Carl has said, there is an implicit call to B's no argument constructor as the first statement in the A(int, int) constructor.
[ August 18, 2003: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Carl Trusiak

Joined: Jun 13, 2000
Posts: 3340
Shoot, thanks Barry, I quick scanned the question and missed the fact that A extended Demo and not B. I assumed it did just by the nature of the question.
subject: superclass' default construct
It's not a secret anymore!