This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Infinite instance creation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Infinite instance creation" Watch "Infinite instance creation" New topic

Infinite instance creation

Kaz Yosh
Ranch Hand

Joined: May 22, 2003
Posts: 63
This is from
The answer is 2,4,5
I think 5 is illegal because it cause infinite loop of creating instance. Any comment?

Consider the following class definitions, which of the following can be placed legally at line 7 without causing any compile time errors? [Check all correct answers]
1. public class Animal {
2. public Animal() {
3. super();
4. }
5. protected Animal (int legs){
6. this();
7. // Insert Code Here
8. }
9. }
10. public class Bird extends Animal {
11. public Bird() {
12. super();
13. }
14. public Bird(int legs) {
15. super(legs);
16. }
17. }

1 super();

2 Animal elephant = new Animal();

3 this(legs);

4 double d = Math.sin((double)legs);

5 Animal p = new Bird(4);

"If anything can go wrong, it will"
Thomas De Vos
stable boy
Ranch Hand

Joined: Apr 12, 2003
Posts: 425
You are right, this will cause an infinite loop, <b>but</B> the code still compiles so it is legal to place the line: Animal p = new Bird(4);

Try your free <a href="" target="_blank" rel="nofollow">SCJP 1.4</a> certification centre.<br />Try your free <a href="" target="_blank" rel="nofollow">SCWCD</a> certification centre.<br />Try your free <a href="" target="_blank" rel="nofollow">SCBCD</a> certification centre.<br />Try your <a href="" target="_blank" rel="nofollow">Websphere (Test 285) </a> certification centre.<br />Try your <a href="" target="_blank" rel="nofollow">SCMAD</a> certification centre. (New)<br /> <br /><a href="" target="_blank" rel="nofollow">Java/J2EE Certification Blogging</a>
I agree. Here's the link:
subject: Infinite instance creation
It's not a secret anymore!