| Author |
Infinite instance creation
|
Kaz Yosh
Ranch Hand
Joined: May 22, 2003
Posts: 63
|
|
This is from javacertificate.com 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="http://www.javacertificate.com" target="_blank" rel="nofollow">SCJP 1.4</a> certification centre.<br />Try your free <a href="http://www.j2eecertificate.com" target="_blank" rel="nofollow">SCWCD</a> certification centre.<br />Try your free <a href="http://www.ejbcertificate.com" target="_blank" rel="nofollow">SCBCD</a> certification centre.<br />Try your <a href="http://www.webspherecertificate.com" target="_blank" rel="nofollow">Websphere (Test 285) </a> certification centre.<br />Try your <a href="http://www.j2mecertificate.com" target="_blank" rel="nofollow">SCMAD</a> certification centre. (New)<br /> <br /><a href="http://blogs.javacertificate.com" target="_blank" rel="nofollow">Java/J2EE Certification Blogging</a>
|
 |
 |
|
|
subject: Infinite instance creation
|
|
|