permaculture playing cards*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt regarding Constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt regarding Constructor" Watch "Doubt regarding Constructor" New topic
Author

Doubt regarding Constructor

Dipti Mishra
Greenhorn

Joined: Jan 24, 2006
Posts: 22
Hi,

While studying I came across this question.

Which statement is true?

Select the one correct answer.

1) A super() or this() call must always be provided explicitly as the first statement in the body of a constructor.

2) If both a subclass and its superclass do not have any declared constructors, the implicit default constructor of the subclass will call super() when run.

3) If neither super() nor this() is declared as the first statement in the body of a constructor, then this() will implicitly be inserted as the first statement.

4)If super() is the first statement in the body of a constructor, then this() can be declared as the second statement.

5)Calling super() as the first statement in the body of a constructor of a subclass will always work, since all superclasses have a default constructor.

As per what I have studied option (1) seems equally rasonable to me.But when i checked the answer it says (2)

Can anyone tell me where am i mistaken?

Regards,
Dipti
Craig Tyler
Ranch Hand

Joined: Jan 15, 2006
Posts: 52
Option 1 is wrong because if you do not add a call to super() or this() explicitly, then a call to super() is implicitly provided for you.

Thus, option 2 is correct since the implicity default constructor will have an implicit call to super() as it's first (and only) statement.
Dipti Mishra
Greenhorn

Joined: Jan 24, 2006
Posts: 22
Hi Craig,

Thanks for the clarification.

Regards,
Dipti
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt regarding Constructor
 
Similar Threads
Q. about constructors (and inheritage)
a question about default constructor
Question on Construtor
constructor
Why Is a No-Arg Constructor Required Here?