wood burning stoves 2.0
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Default Constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Default Constructor" Watch "Default Constructor" New topic

Default Constructor

Deepak Jindal
Ranch Hand

Joined: Nov 16, 2000
Posts: 30
class First {
public First (String s) {
public class Second extends First {
public static void main(String args []) {
new Second();
What is the result of compiling and running the Second class?
A.Nothing happens
B.A string is printed to the standard out
C.An instance of the class First is generated
D.An instance of the class Second is created
E.An exception is raised at runtime stating that there is no null parameter constructor in class First.
F.The class second will not compile as there is no null parameter constructor in the class First
Select the most appropriate answer.
The answer is E. My argument is: won't the default constructor be created by JVM.
Priya Kannan
Ranch Hand

Joined: Jan 19, 2001
Posts: 72
Hi Deepak,
A default constructor can be created in the Second class ,but when the implicit super() is fired from the Second's default constructor there is no matching constructor in the class First!.
Also a default constructor is created in the class First only if there's no other constructor, defined in that class.But First has already got a constructor and that means...A compile time error!
Deepak Jindal
Ranch Hand

Joined: Nov 16, 2000
Posts: 30
Thanks Priya.
natarajan meghanathan
Ranch Hand

Joined: Feb 01, 2001
Posts: 130
The answer should be F. not E. It won't compile since the superclass does not have a default constructor.

Sun Certified Programmer for Java 2 Platform
Sean Casey
Ranch Hand

Joined: Dec 16, 2000
Posts: 625
The answer is indeed F, a compile time error as Priya has already pointed out.
I agree. Here's the link: http://aspose.com/file-tools
subject: Default Constructor
jQuery in Action, 3rd edition