aspose file tools*
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "default constructor??" Watch "default constructor??" New topic
Author

default constructor??

srikanth reddy
Ranch Hand

Joined: Jul 28, 2005
Posts: 252
Which of the following are true about the "default" constructor? Select 2 correct options
(1) It is provided by the compiler only if the class does not define any constructor
(2) It initializes the instance members of the class
(3) It calls the default 'no-args' constructor of the super class
(4) It initializes instance as well as class fields of the class
(5) It is provided by the compiler if the class does not define a 'no- args' constructor

my doubt is why not 2 is correct .....


Thanks & Regards<br /> <br />-Srikanth
Mausam M Kakkad
Ranch Hand

Joined: Oct 27, 2005
Posts: 40
Hi Srikanth,

If I'm not wrong 1,2,3 is the answer.....right!!!
And I've gone through JLS, I dint find any reason for 2 to be incorrect..

But, can we think of the question like....they have asked for 2 correct answer they havent specified total how many answers are true...

they have asked for 2...give 2 correct answers....

correct me if I'm thinking on wrong lines

Regards,
Mausam
srikanth reddy
Ranch Hand

Joined: Jul 28, 2005
Posts: 252
the mock hasnt specified ..even if sepcified what u will select coz i feel 123 are all correct .....
manogna edintipal
Ranch Hand

Joined: Aug 16, 2005
Posts: 51
Hi,

I have had to take a hard look at the statements...

and came up with ..2,3..

Felt 1..as correct...

except if you dont consider anonymous class..

An anonymous inner class doesnt have a constructor...only instance initializer



Sanju
harish shankarnarayan
Ranch Hand

Joined: Sep 12, 2005
Posts: 158
default constructor-It initializes the instance members of the class



can any one explain me this point ,it may be trivial one but .....
explain with example


Harish<br />SCJP 1.4 (85%)
Sowjanya Chowdary
Ranch Hand

Joined: Aug 22, 2005
Posts: 35
I think (1) and (3) are correct about default constructor.

(2) is wrong because default constructor has nothing defined
its body
(4) and (5) are self explanatory.

Please correct me if i am wrong.
harish shankarnarayan
Ranch Hand

Joined: Sep 12, 2005
Posts: 158
i feel the same..Amrutha
thats why have asked for explanation
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19718
    
  20

Originally posted by manogna edintipal:

An anonymous inner class doesnt have a constructor...only instance initializer

Yes it does - only you can't define any.

Consider this case:

There is a constructor, that takes a String. There are even constructors that take an Icon, or a String and an Icon, or any other constructor AbstractAction has.
As for anonymous classes implementing interfaces (new ActionListener() ...), there is also a constructor - a non-arg constructor.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ray Horn
Ranch Hand

Joined: Oct 20, 2005
Posts: 39
(2) It initializes the instance members of the class
...
my doubt is why not 2 is correct .....


Seems two books I checked agree with you:
From Core Java (J2SE 5.0) , Volume I, Page 128


If you write a class with no constructors whatsoever, then a default constructor is provided for you. This default constructor sets all the instance fields to their default values. So, all numeric data contained in the instance fields would be 0, all Booleans would be false, and all object variables would be set to null.


From K&B 1.4. Page 314 when they discuss constructor chaining they also say:


5. Object constructor completes
6. Animal instance variables are given their explicit values (if any)
7. Animal constructor completes


Where did you get the question from? Do they provide any answer?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: default constructor??