QUESTION 9 Given: 1. package geometry; 2. 3. public class Hypotenuse { 4. public InnerTriangle it = new InnerTriangle(); 5. 6. class InnerTriangle { 7. public int base; 8. public int height; 9. } 10. } Which statement is true about the class of an object that can reference the variable base? A. It can be any class. B. No class has access to base. C. The class must belong to the geometry package...
QUESTION 8 Given: 01. public class Hello { 02. String title; 03. int value; 04. 05. public Hello() { 06. title += " World"; 07. } 08. 09. public Hello(int value) { 10. this.value = value; 11. title = "Hello"; 12. Hello(); 13. } 14. } and: Hello c = new Hello(5);System.out.println(c.title); What is the result? A. Hello B. Hello World C. Compilation fails. D. Hello World 5 E. The code runs with no..
QUESTION 7 Which four statements are true? (Choose four.) A. Has-a relationships should never be encapsulated. B. Has-a relationships should be implemented using inheritance. C. Has-a relationships can be implemented using instance variables. D. Is-a relationships can be implemented using the extends keyword. E. Is-a relationships can be implemented using the implements keyword. F. The relations..
QUESTION 6 Given: 1. 2. public class Hi { 3. void m1() { } 4. protected void m2() { } 5. } 6. class Lois extends Hi { 7. // insert code here 8. } Which four code fragments, inserted independently at line 7, will compile? (Choose four.) A. public void m1() { } B. protected void m1() { } C. private void m1() { } D. void m2() { } E. public void m2() { } F. protected void m2() { } G. private void m2..
QUESTION 5 Given: 10. interface A { void x(); } 11. class B implements A { public void x() {} public void y() {} } 12. class C extends B { public void x() {} } And: 20. java.util.List list = new java.util.ArrayList(); 21. list.add(new B()); 22. list.add(new C()); 23. for (A a : list) { 24. a.x(); 25. a.y(); 26. } What is the result? A. The code runs with no output. B. An exception is thrown at r..
QUESTION 4 Given: 1. class Mammal { 2. } 3. 4. class Raccoon extends Mammal { 5. Mammal m = new Mammal(); 6. } 7. 8. class BabyRaccoon extends Mammal { 9. } Which four statements are true? (Choose four.) A. Raccoon is-a Mammal. B. Raccoon has-a Mammal. C. BabyRaccoon is-a Mammal. D. BabyRaccoon is-a Raccoon. E. BabyRaccoon has-a Mammal. F. BabyRaccoon is-a BabyRaccoon. Solution : ABCF