Page: 2
8. OOPs
Q: 05 Click the Task button. 
Solution: class A has name A class B hasname A Q: 06 Which two statements are true about has-a and is-a relationships? (Choose two.) A. Inheritance represents an is-a relationship. B. Inheritance represents a has-a relationship. C. Interfaces must be used when creating a has-a relationship. D. Instance variables can be used when creating a has-a relationship. Answer: A, D Q: 07 Given: 10: public class Hello { 11: String title; 12: int value; 13: public Hello() { 14: title += " World"; 15: } 16: public Hello(int value) { 17: this.value = value; 18: title = "Hello"; 19: Hello(); 20: } 21: } and: 30: Hello c = new Hello(5); 31: 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 output. F. An exception is thrown at runtime. Answer: C Q: 08 Given: 1. class Super { 2. private int a; 3. protected Super(int a) { this.a = a; } 4. } ... 11. class Sub extends Super { 12. public Sub(int a) { super(a); } 13. public Sub() { this.a = 5; } 14. } Which two, independently, will allow Sub to compile? (Choose two.) A. Change line 2 to: public int a; B. Change line 2 to :protected int a; C. Change line 13 to :public Sub() { this(5); } D. Change line 13 to :public Sub() { super(5); } E. Change line 13 to :public Sub() { super(a); } Answer: C, D Q: 09 Click the Task button. 
Solution: Car is a Vehicle class A and < ==================> implements B , C car is a Collectable { } Car has a < ==================> class A { Steering Wheel B b; } car has Wheels < ==================> class A{ List <B> b; } Mini is a Car < ==================> class A extends B{ } Car is an Object < ==================> class A { }
Page: 2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|