File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes About MarcusGreen Test 3 Question43 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "About MarcusGreen Test 3 Question43" Watch "About MarcusGreen Test 3 Question43" New topic
Author

About MarcusGreen Test 3 Question43

RKB
Greenhorn

Joined: Aug 14, 2000
Posts: 9
Hi,
Question 43)
Which of the following statements are true
1) constructors cannot be overloaded
2) constructors cannot be overridden
3) a constructor can return a primitive or an object reference
4) constructor invocation occurs from the current class up the hierarchy to the ancestor class
Answer to Question 43)
2) constructors cannot be overriden
_________________________________________________________________
The explanation to why choice 4 is wrong is
Option 4 is the inverse of what happens as constructors are called from the oldest ancestor class downwards. You can test this by writing a class that inherits from a base class and getting the constructor to print out a message. When you create the child class you will see the order of constructor calling.
_________________________________________________________________
My thought was the child class constructor calls the superclass constructor ,
superclass constructor in turn calls the sperclass constructor and so on .
This is done since super() [implicitly by compiler or explicitly by programmer] or
super( parameters )[explicitly by programmer] is called.
So I think the constructors are called from child to parent that is from current class to ancesstor class.
[This happens Exactly like method calls.]
So i think choice 4 is also correct .
Please somebody give suggestions.
Tinu
deekasha gunwant
Ranch Hand

Joined: May 06, 2000
Posts: 396
Hi RKB,
as u know that the at the begining of the constructor a call to super class constructor is made. which means that first of all the higher level constructors are invoked and executed only after that the body of a constructor is executed.
so from this perspective 4) is wrong.

regards
deekasha
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I think the wording option 4 is a bit vague, but I agree with the outcome. The child class ctors get a chance to specify which version of the parent ctor gets called (if there are overloaded versions), but the real work of the child ctor (i.e., of the rest of its body) won't be run until the all of its parents are constructed. So, there is an initial stop-off at the child ctor, but that's about it.
IMHO, I don't like how Java handles this. It seems strange that you put the call to a parent-class ctor (or to an overloaded sibling ctor) in the ctor body, itself. I know that in C++, you have an intialization list (placed where you'd put a "throws" clause) from which you can make a call to the parent ctor, and I think that is a cleaner, more elegant way to make your explicit ctor calls clearly distinct from the rest of the ctor code in the child class.
RKB
Greenhorn

Joined: Aug 14, 2000
Posts: 9
Hi Dab,
Originally posted by DaB:
I think the wording option 4 is a bit vague, but I agree with the outcome.

I agree with u.
The option 4 is ture since the coding is
4) constructor invocation occurs from the current class up the hierarchy to the ancestor class
The option 4 is wrong if the coding is
4) constructor execution is completedoccurs from the current class up the hierarchy to the ancestor class
Correct me if I am wrong,
Tinu
[This message has been edited by RKB (edited September 01, 2000).]
[This message has been edited by RKB (edited September 01, 2000).]
[This message has been edited by RKB (edited September 01, 2000).]
[This message has been edited by RKB (edited September 01, 2000).]
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
RKB,
Well, I suppose I could go either way with the original wording, but I think your second version makes the option true!
The underlying idea here is that an object is actually built from the top down. If you think about it a bit, it makes sense to construct objects that way: consider an inherited method and where it comes from (hint: a parent), and think about the dangers of calling an overridden method in a constructor...
And, objects in Java are probably destroyed in the opposite order (i.e., bottom-up), but I have to check on that.
Don
[This message has been edited by DaB (edited September 01, 2000).]
RKB
Greenhorn

Joined: Aug 14, 2000
Posts: 9
Hi DaB,
I made a mistake and I corrected the statement.
Tinu
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: About MarcusGreen Test 3 Question43
 
Similar Threads
Marcus Green's exam 3 question
I think it should be false.
Marcus Green's Mock 3 Q43.
constructors??
Marcus mock 3 No.43