P. 1
2 Oops

2 Oops

|Views: 0|Likes:
Published by sabarin_72

More info:

Published by: sabarin_72 on Apr 08, 2013
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

04/08/2013

pdf

text

original

Object-oriented programming (OOPs

)
For more details on SUN Certifications, visit JavaScjpDumps Ques: 01 Given: public class Plant { private String name; public Plant(String name) { this.name = name; } public String getName() { return name; } } 1. public class Tree extends Plant { 2. public void growFruit() { } 3. public void dropLeaves() { } 4. } Which statement is true? A. The code will compile without changes. B. The code will compile if public Tree() { Plant(); } is added to the Tree class. C. The code will compile if public Plant() { Tree(); } is added to the Plant class. D. The code will compile if public Plant() { this("fern"); } is added to the Plant class. E. The code will compile if public Plant() { Plant("fern"); } is added to the Plant class. Answer: D Ques: 02 Click the Task button.

Solution: Alpha.foo Beta.ba Beta.foo Beta.bar

Ques: 03 Given: 11. public class Yikes { 12. 13. public static void go(Long n) {System.out.println("Long ");} 14. public static void go(Short n) {System.out.println("Short ");} 15. public static void go(int n) {System.out.println("int ");} 16. public static void main(String [] args) { 17. short y = 6; 18. long z = 7; 19. go(y); 20. go(z); 21. } 22. } What is the result? A. int Long B. Short Long C. Compilation fails. D. An exception is thrown at runtime. Answer: A Ques: 04 Click the Exhibit button. Which statement is true about the classes and interfaces in the exhibit?

A. Compilation will succeed for all classes and interfaces. B. Compilation of class C will fail because of an error in line 2. C. Compilation of class C will fail because of an error in line 6. D. Compilation of class AImpl will fail because of an error in line 2. Answer: C

Ques: 05 Click the Task button.

Solution: class A has name A class B hasname A Ques: 06 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();

D Ques: 09 Click the Task button. class Sub extends Super { 12. } Answer: C. An exception is thrown at runtime. D. Inheritance represents a has-a relationship.20: } 21: } and: 30: Hello c = new Hello(5). public Sub() { this. B. } 13. 11. Interfaces must be used when creating a has-a relationship. The code runs with no output. C. Answer: A. Hello World 5 E. 31: System.) A. D Ques: 08 Given: 1.a = 5. } E. } Which two. Change line 13 to :public Sub() { super(a). B. Hello B. } D. Change line 13 to :public Sub() { this(5). Instance variables can be used when creating a has-a relationship. Change line 2 to: public int a. independently. } . will allow Sub to compile? (Choose two.. Answer: C Ques: 07 Which two statements are true about has-a and is-a relationships? (Choose two. class Super { 2. public Sub(int a) { super(a).. . What is the result? A. Change line 13 to :public Sub() { super(5).println(c. F.title).) A. } 4. Inheritance represents an is-a relationship. D. Compilation fails. } 14.a = a. Change line 2 to :protected int a. C.out. protected Super(int a) { this. 3. private int a. Hello World C.

interface C extends A. public void bMethod(){} 6. interface B { public void bMethod(). } 7. } 4. class D implements B { 5. public void cMethod(){} 11. class E extends D implements C { 8. interface A { public void aMethod().Solution: Car is a Vehicle and car is a Collectable Car has a Steering Wheel car has Wheels class A < ==================> implements B . } class A extends B{ } class A { } < ==================> Mini is a Car Car is an Object < ==================> < ==================> Ques: 10 Given: 1. } . } 3. } 2. C { } < ==================> class A { B b. public void aMethod(){} 9. public void bMethod(){} 10.B { public void cMethod(). } class A{ List <B> b.

class ClassA { 2. public static void main(String[] args) { 12. E. } 6. C.bMethod() invokes the version of bMethod() defined in Line 5. Compilation fails because of an error in line 3. Constructors CANNOT use the private modifier. 420 is the output. Base b = new Base(). public class Base { 2. 10. If you define D e = (D)(new E()). . Compilation fails because of an error in line 7. 3. Constructors CANNOT use the protected modifier. } 11. 3.bMethod() invokes the version of bMethod() defined in Line 9. private ExtendedA(int numberOfInstances) { 9. B. public class ExtendedA extends ClassA { 8. Answer: F Ques: 11 Given: 1. } Which statement is true? A. System. Sub s = new Sub(). Compilation fails because of an error in line 9. public static final String FOO = "foo". An exception is thrown at runtime. All constructors must be declared public. F.numberOfInstances). public static void main(String[] args) { 4. then e. E. If you define D e = (D)(new E()). then e. } 7.numberOfInstances = numberOfInstances. this.print(ext. protected ClassA(int numberOfInstances) { 4. Answer: A Ques: 12 Given: 1. B.What is the result? A. ExtendedA ext = new ExtendedA(420). D.out.bMethod() invokes the version of bMethod() defined in Line 5. super(numberOfInstances). } 15. 5. 5. If you define D e = new E(). 13. C. D. public int numberOfInstances. then e. 14.

test(null). An encapsulated class allows a programmer to change an implementation without affecting outside code.print(Sub.print(((Base)s).out.print(Base. Answer: A Ques: 15 Given: . D Ques: 14 Given: 11. public class promotes re-use. foofoofoobarfoo Answer: D Ques: 13 Which two statements are true? (Choose two. if (str == null | str. C. Answer: A. C.FOO). } 17. foobarfoofoofoo D. System. What is the result? A. B. B. System. public static void test(String str) { 12.println("String is empty"). class Sub extends Base {public static final String FOO="bar".6.out. 7. 10. 16. } else { 15. 9. System. } And the invocation: 31. foofoofoobarbar G. D. foobarfoobarfoo E.out.FOO). An exception is thrown at runtime.print(s. foobarfoobarbar C.out. foofoofoofoofoo B. 14. System.out.out. barbarbarbarbar F. 8. "String is empty" is printed to output. An encapsulated class allows subclasses to overload methods.print(b.length() == 0) { 13. but does NOT allow overriding methods.FOO).FOO). Compilation fails because of an error in line 12. Classes that share the same interface are always tightly encapsulated.println("String is not empty").) A. An encapsulated.FOO). System.} What is the result? A. "String is not empty" is printed to output. D.out. } } 12. 11. System. System.

} 22.setX( 100 ). o. public static void main(String [] args) { 17. 18. 20. short LONG B. i. i. 21. E. public static void go(Long n) {System.out.out. n = 100.out.setY( i ). Which three code fragments. o. int z = 7.setX( 100 ). go(y).setX( 100 ).getY().} 16. go(z). C.println("SHORT"). i. i = new Inner(). . i = new Inner(). public static void go(short n) {System. D. added individually at line 29.println(" LONG").setX( 100 ).12. An exception is thrown at runtime. SHORT LONG C.} 14. } What is the result? A.) A. D.println("short"). public static void go(Short n) {System. public class Wow { 13. 19. produce the output 100? (Choose three. B. Answer: C Ques: 16 Click the Exhibit button. Short y = 6.} 15. Compilation fails.

print(1). public Three() { System.setX( 100 ). public Two() { System. } 15.F. } What is the result when this code is executed? A. public class Numbers{ 20. The code runs with no output. F Ques: 17 Given: 10.setY( i ). 3 C. 123 D.out. class Two extends One { 14. 1 B. class Three extends Two { 17. Answer: B. } 19.out. Answer: C Ques: 18 Click the Exhibit button. public One() { System. 321 E. } 12. class One { 11. C. } 13. } 18. i.print(3). o.print(2).out. What is the outcome of the code? . public static void main( String[] argv ) { new Three(). } 21. i = new Inner(). } 16.

public int foo() { return 3. // insert method here 18. B. public Two foo() { return this. Scrumdiddlyumptious Answer: B Ques: 19 Given: 10. Gobstopper Fizzylifting C. class One { 11. public One foo() { return this. } 16.A. } C. } 12. } Which two methods. Scrumdiddlyumptious Fizzylifting E. correctly complete the Three class? (Choose two. public One foo() { return this. Compilation fails. Gobstopper Scrumdiddlyumptious D. } . class Three extends Two { 17. class Two extends One { 14.) A. inserted individually. public void foo() {} B. } 13. } 15.

} Answer: C. 300-100-100-100-100 B. . 300-300-100-100-100 C. public Object foo() { return this. } E.D. D Ques: 20 Click the Exhibit button. 300-300-300-100-100 D. public One foo() { return this. What is the output of the program shown in the exhibit? A. 300-300-300-300-100 Answer: B Ques: 21 Click the Task button.

} public void bar(int x. public void add(A a. D Ques: 23 Click the Exhibit button. } Answer: B. } 14. } C.getValue(). } 13.getValue().) A. // insert code here 16. } B.getValue(). interface A { public int getValue(). } E. public void add(A a) { a.getValue().Solution: public void bar(int x){ } public int bar(String x){ return 1. inserted individually at line 15. } 11. } Which three code fragments. What is the result? . B b) { a. } D.int y) { } Ques: 22 Given: 10. public void add(C c) { c.getValue(). class C extends B { 15. make use of polymorphism? (Choose three. C c2) { c1. C. class B implements A { 12. public int getValue() { return 1. public void add(C c1. public void add(B b) { b.

A z = new C(). D.a1(). snootchy 420 third second first B. 12.A.a2(). . abstract class A { 11. third second first snootchy 420 E. first second first third snootchy 420 Answer: D Ques: 24 Given: 10. C y = new C(). z. } 14. abstract void a1(). B. class B extends A { 15. x.c1(). void a1() { } 16. z. snootchy 420 first second third C. } 18. void a2() { } 17. third first second snootchy 420 F. z.) A. What are four valid examples of polymorphic method calls? (Choose four. C.a2(). first second third snootchy 420 D. class C extends B { void c1() { } } and: A x = new B(). void a2() { } 13.

F.ownerName = ownerName. F Ques: 25 Click the Exhibit button. 22. 28. this. C.c1(). public void setCardInformation(String cardID. Value is: 12 D. 26. 31. y. public String ownerName. Answer: A.E. F.a1(). this. this. public class CreditCard { 21. Compilation fails. 23. An exception is thrown at runtime. private Integer limit.cardID = cardID. Value is: 8 B. The code runs with no output. String ownerName. . private String cardID. 30. D. Integer limit) { 29. 27. Answer: A Ques: 26 Given: 20. 24. Value is: -12 E. 25. What is the result? A.limit = limit. x. B.

} 15. Answer: C Ques: 27Given: 11. bark C.. meow D. What is the result? A. D. class Animal { public String noise() { return "peep". E. C. Answer: E Ques: 28 Click the Task button. Compilation fails. Animal animal = new Dog(). The ownerName variable breaks encapsulation.println(cat. The class is fully encapsulated. . class Cat extends Animal { 16. 32. public String noise() { return "meow". peep B. } Which statement is true? A. The setCardInformation method breaks encapsulation. } 17.out. Cat cat = (Cat)animal.32. class Dog extends Animal { 13. 30. The code demonstrates polymorphism. } } 12. } . } 14. } 33.. 31. The cardID and limit variables break polymorphism. public String noise() { return "bark". B. System. An exception is thrown at runtime.noise()). E.

C. Has-a relationships can be implemented using instance variables.) A. . B. A private static method can be called only within other static methods in class X. A method with the same signature as a private final method in class X can be implemented in a subclass of X. Has-a relationships should never be encapsulated. A public static method in class X can be called by a subclass of X without explicitly referencing the class X. Answer: B. D. Is-a relationships can be implemented using the extends keyword. Has-a relationships should be implemented using inheritance. F Ques: 30 Which four statements are true? (Choose four. E. A protected method in class X can be overridden by any subclass of X. G.Solution: Dog Forest Rectangle JavaBook is-a has-a has-a is-a Animal Tree Side ProgrammingBook Ques: 29 Which three statements are true? (Choose three.) A. F. A protected method in class X can be overridden by a subclass of A only if the subclass is in the same package as X. E. A final method in class X can be abstract if and only if X is abstract. A non-static public final method in class X can be overridden in any subclass of X. E. Is-a relationships can be implemented using the implements keyword. B. D. C.

Beagle has-a Jumper Answer: B. D. Dog is-a Animal D. class Beagle extends Dog implements Jumper{ 41. } .F.. 32. Cat has-a Animal F. Dog is-a Jumper E. public void jump() {} 52. } . The relationship between Movie and Actress is an example of an is-a relationship.. Beagle has-a Tail G. } Which three are true? (Choose three.. Cat is-a Animal B. 40.) .) A. G Ques: 31Given: 10.. class Cat implements Jumper{ 51. 20. interface Jumper { public void jump(). What two must the programmer do to correct the compilation errors? (Choose two. C. public void jump() {} 42... 30. Answer: C. class Dog extends Animal { 31. class Animal {} . 50.. F Ques: 32 Click the Exhibit button. E. Cat is-a Jumper C.. An array or a collection can be used to implement a one-to-many has-a relationship. G. } . Tail tail.

2)). b). public static int multiply(int a. insert a call to super() in the MeGo constructor D. } and: 20. } and: 30.out. 32. 23. public class SuperCalc { 11.A. int b) { 22.} 12. protected static int multiply(int a. System. change line 3 in the MeGo class to super. insert a call to super(vin) in the MeGo constructor E.out.multiply(a.multiply(3. insert a call to this() in the MeGo constructor C. SubCalc sc = new SubCalc (). 24. System. int c = super. Answer: D. E Ques: 33 Given: 10. change the wheelCount variable in Car to protected F.wheelCount = 3. public class SubCalc extends SuperCalc{ 21. return c.4)). 31.multiply(2. insert a call to this() in the Car constructor B.println(sc. What is the result? . int b) { return a * b.println(SubCalc. } 25.

Pizza pizza = new PepperoniPizza(). public int blipvert(int x) { return 0.addTopping("Mushrooms"). 3. inserted independently at line 5. public void addTopping(String topping) { 9. } 15. } E. pizza. protected long blipvert(int x. } 4. protected int blipvert(int x) { return 0. class Vert extends Blip { 5. D. } 11. Compilation fails because of an error in line 21.util. } 3. private int blipvert(long x) { return 0. G Ques: 35 Given: 1. E.out. public final void addTopping(String topping) { 4. } Answer: A. 5. C. E. } 7. 10. 14. will compile? (Choose five.add(topping). } F. } Which five methods. private int blipvert(int x) { return 0. toppings. C.A. protected long blipvert(long x) { return 0. int y) { return 0. } D. The code runs with no output.) A. } What is the result? . 13. } G.ArrayList toppings. Answer: E Ques: 34 Given: 1. public class PepperoniPizza extends Pizza { 8. } B.public class Blip { 2. public static void main(String[] args) { 12. java. Compilation fails because of an error in line 22.println("Cannot add Toppings"). protected int blipvert(long x) { return 0. System. } C. // insert code here 6. protected long blipvert(int x) { return 0. } 6. 12 4 B. class Pizza { 2. F. F. Compilation fails because of an error in line 31. An exception is thrown at runtime.

int high). interface DoMore { 5. B. The code runs with no output. } } 11. abstract class DoAbstract implements DoStuff2. 4. } 3. interface DoAll extends DoMore { . } 6. float getRange(int low. interface DoStuff2 { 2.14f. D. float getAvg(int a. 7. A NullPointerException is thrown in Line 4. int c). 9. 12. int b. Answer: A Ques: 36 Given: 1. class DoStuff implements DoStuff2 { 10. public float getRange(int x.A. Cannot add Toppings C. DoMore { } 8. int y) { return 3. Compilation fails.

An exception is thrown at line 26 at runtime. and 13 contain errors. int c. Compilation fails. Compilation of class A will fail due to an error in line 6. float getAvg(int a.doit(4. Compilation fails.out. Only line 12 contains an error.println(a. . Compilation fails. Compilation fails. } What is the result? A. 12. public void start() { System. } What is the result? A. Given: 25. Compilation fails. } 3. E. G. ((TestA)new TestB()). The file will compile without error. B. Only line 7 contains an error. int d).println("TestB"). Line 26 prints "a" to System.out. An exception is thrown at runtime. Compilation fails. A a = new A(). } 9. C. 5)). } 6. D. Answer: A Ques: 37 Given: 1. TestB C. } 4. Compilation fails. Only lines 7 and 13 contain errors. D. C. TestA B. D. public class TestB extends TestA { 5. Lines 7. Only lines 7 and 12 contain errors. F. class TestA { 2.out. public void start() { System. System.out. 8. public static void main(String[] args) { 7. What is the result? A. B. Answer: B Ques: 38 Click the Exhibit button.println("TestA").13. int b. Only line 13 contains an error.start(). Line 26 prints "b" to System.out. 26.

13. The attribute id in the Item object remains unchanged. E. F. } What is the result? A. Compilation fails because of an error in line 4. 20. } 2. public ItemTest(int id) { this. private final int id. An exception is thrown at runtime. Compilation fails because of an error in line 1. }). Answer: A Ques: 40 Given: 11. null C. An exception is thrown at runtime. The attribute id in the Item object is modified to the new value. public String toString() { return "test". ItemTest fa = new ItemTest(42).id = id. 19. E. class One { 11. Compilation fails.id). 16.println(new TestA() { 5.Answer: A Ques: 39 Given: 1. System. public static void main(String[] args) { 17. public class Test { 3. public static void main(String[] args) { 4. B.println(fa. public class ItemTest { 12. void foo() { } . D. test B. } 21. 18. Compilation fails because of an error in line 5. } What is the result? A. interface TestA { String toString().out.updateId(69). 7. } 14. public void updateId(int newId) { id = newId.out. fa. } 8. } 15. Answer: A Ques: 41 Given: 10. D. System. C. A new Item object is created with the preferred value in the id attribute. } 6.

class Two extends One { 14. . public class Employee extends Info implements Data public void load(){ /*do something*/ } public void Info.12. public class Employee implements Info extends Data { public void load() { /*do something*/ } } C. C. 13. } 13. public class Employee extends Info implements Data{ public void Data. } Which class correctly uses the Data interface and Info class? A.) A. int x. public void foo() { /* more code here */ } D. void foo() { /* more code here */ } C. //insert method here 15. 14. interface Data { public void load(). int foo() { /* more code here */ } B. public abstract class Shape { 12.load() { /*do something*/ } public void Info. public class Employee implements Info extends Data { public void load(){ /*do something*/ } public void Info.load(){ /*do something*/ } } F. will correctly complete class Two? (Choose three. inserted individually at line 14.load(){ /*do something*/ } public void load(){ /*do something*/ } } E. public abstract void draw(). public class Employee extends Info implements Data { public void load() { /*do something*/ } } B. } 11. abstract class Info { public abstract void load(). public class Employee implements Info extends Data { public void Data. protected void foo() { /* more code here */ } Answer: B.load() { /*do something*/ } } Answer: A Ques: 43 Given: 11. } Which three methods. private void foo() { /* more code here */ } E. int y. E Ques: 42 Given: 10.load(){ /*do something*/ } } D.

Answer: D . D. this. this. s. s. An exception is thrown at runtime. 17. s->draw(). int y) { 16. 0000 C. } 19.Shape.setAnchor(10. s. Which is correct? A.15. 18. C. s.setAnchor(10. What is the result? A.10). s->setAnchor(10. Compilation fails because of an error in line 18. E.10).10). Circle c = new Shape(). 4321 B.draw(). c. } and a class Circle that extends and fully implements the Shape class.10).draw().draw(). c. Shape s = new Circle().Shape.10).setAnchor(10. D. c. c.draw().y = y.x = x.setAnchor(10. public void setAnchor(int x. Shape s = new Circle(). B. Circle c = new Circle(). Answer: C Ques: 44 Click the Exhibit button. Shape s = new Shape().

} 14. } 17. Compilation will succeed if A extends B. Compilation will always fail because of an error in line 8. } 13. inserted at line 16. C. return new B(). void process() throws Exception { throw new Exception(). Answer: B Ques: 47 Given: 11. public static void main( String[] args ) { 15. } Which statement is true? A.ClassCastException? A. } 18. void process() { System. B.out.Ques: 45 Given: 10. Alpha a = x. public B getA(){ 8. class Beta extends Alpha {} 13. interface Foo {} 11. D.lang. static class B extends A { 15. // insert code here 17. 16. class SubClass extends SuperClass { 7. class Delta extends Beta { 14. C. 4. } 6. public A getA() { 3. Foo f = (Alpha)x. Beta x = new Beta(). Compilation will always fail because of an error in line 7. } 5. } 10. class Alpha implements Foo {} 12. } Which code. will cause a java. B. Beta b = (Beta)(Alpha)x. 9. return new A().println("B"). D. class SuperClass { 2. Foo f = (Delta)x. } 16. public static void main(String[] args) { . static class A { 12. Compilation will succeed if B extends A. Answer: B Ques: 46 Given: 1.

ClassA p4 = new ClassC().out. class ClassC extends ClassA {} and: 21.speed()). D. 0. 22. 19. C. System. F. ClassB p1 = new ClassB(). F Ques: 49 Given: 11. 23. RaceCar racer = new RaceCar(). B. 25. B B. 23. new B(). } 13. 150. 0 C. 0. What is the result? A. Car car = new RaceCar(). Compilation fails because of an error in line 15. class ClassB extends ClassA {} 13. p1 = (ClassB)p3. 150. C. 24. 150 . class RaceCar extends Car { public int speed() { return 150. E. 60.18. D. E.. + ". ClassA p3 = new ClassB().) A. The code runs with no output. p0 = p1.speed() 25. 21. Compilation fails because of an error in line 12.speed() + ". D. ClassA p0 = new ClassA(). 0 B. E. 24. Which three are valid? (Choose three. Compilation fails. class Car extends Vehicle { public int speed() { return 60. 150. Compilation fails because of an error in line 18. abstract class Vehicle { public int speed() { return 0. class ClassA {} 12. Answer: A Ques: 48 Given: 11. p2 = (ClassC)p4. } 12.println(racer. " + car. p2 = (ClassC)p1. } What is the result? A. " + vehicle.process(). Vehicle vehicle = new RaceCar(). Answer: A. } . p1 = p2. p2 = p4. 22. ClassC p2 = new ClassC()..

An exception is thrown at runtime. } 23. class Man { private Dog bestFriend. F. class Man extends Dog { } B. E. public void addFive() { this. } 13. class Man implements Dog { } C. 12. class Man { private Dog<bestFriend>. ). 22. What is the result? A. Answer: A Ques: 51 Which Man class properly represents the relationship "Man has a best friend who is a Dog"? A.println("Value: " + foo. public Bar() { a = 8. 17.a += 5. 31. Value: 8 C. public class Sprite { 12.a).} 14. } D. public int a. } Answer: D Ques: 52 Given: 10. interface Foo { int bar(). Value: 3 B. An exception is thrown at runtime. public int fubar( Foo foo ) { return foo. class Man { private BestFriend<dog>.E. } . } 11. 32. } 24. fubar( 15. Answer: D Ques: 50 Given code in separate source files: 10.addFive(). // insert code here 16. } invoked with: 30. public class Bar extends Foo { 21. Compilation fails. The code runs with no output.bar(). } E. public Foo() { a = 3. public void addFive() { a += 5. class Man { private BestFriend dog. } and: 20. } 13. } F.out. public class Foo { 11. public void testFoo() { 14. Foo foo = new Bar(). Value: 13 D. System. foo. public int a.

} 4. } Which code.18. package packageA. Ques: 54 Given classes defined in two different files: 1. h 3. new class Foo { public int bar() { return 1.Message { . package packageB. Foo { public int bar() { return 1. } B. } Answer: C Ques: 53 Click the Task button. } and: 1. } C. amount. 2. } D. Solution: 1. 2. public class Message { 3. int 2. new Foo() { public int bar() { return 1. new Foo { public int bar() { return 1. inserted at line 15. String getText() { return "text". public class XMLMessage extends packageA. allows the class Sprite to compile? A.

out. 1. Stone c = new Stone(). } 12.3. Answer: C Ques: 56 Click the Exhibit button.getText()). Answer: D Ques: 55 Given: 1. Sente a = new Sente(). public static void main(String[] args) { 3. . Goban b = new Goban(). 9. public void doit() { 3. } 7.out. Compilation fails because of an error in line 4. } 7.go(). Compilation succeeds and no runtime errors with class A occur. public double doit(int x) { 8.go(). public class GoTest { 2.} 4. a. public void go() { System. Compilation fails because of an error in line 3 of XMLMessage. C. text B. Compilation fails because of an error in line 7. An exception is thrown at runtime. public class A { 2. } 8. } 11. public static void main(String[] args) { 5. } 7. class Sente implements Go { 10. 4. b. } 4. C.go().0. An exception is thrown at runtime. 6.”). Compilation fails because of an error in line 2 of XMLMessage. D. String getText() { return "<msg>text</msg>".println(new XMLMessage(). } What is the result? A.main? A. } 10.println(”go in Sente. return "a". c. 6. 6. public String doit() { 5. 5. B. 9. } What is the result of executing XMLMessage. D. System. return 1.

go in Sente go in Sente go in Goban C. class Goban extends Sente { 14. 6. 3.baseSalary = baseSalary. String name. interface Go { public void go(). class Stone extends Goban implements Go { } 18. inserted at line 7. public class Salesperson extends Employee { 2. } 15. 3. this.println(”go in Goban”).13. this. B. } 8.out. public class Employee { 2. double commission) { 5. } Which code. double baseSalary) { 5. double commission. .name = name. public void go() { System. 4. // insert code here 6. Employee(String name. Compilation fails because of an error in line 17. 19. 1. double baseSalary. go in Goban go in Sente go in Sente B. } 16. go in Sente go in Goban go in Goban D. } What is the result? A. } 7. this. 7. 4. } And: 1. Answer: C Ques: 57 Click the Exhibit button. go in Goban go in Goban go in Sente E. 17. public Salesperson(String name. completes the Salesperson constructor? A. double baseSalary.commission = commission. superb().

toString(weight).commission = commission. this. super(name. public class Team extends java. public void compete(Team opponent) { /* more code here */ } 6. 23. 4. E. This code will compile. this. F. } 17. super(). public static void main(String[] args) { . This code demonstrates proper design of an is-a relationship. } 22. private int weight. public class TestPayload { 19. class Payload { 12. This code demonstrates proper design of a has-a relationship. /* insert code here */ 21.commission = commission. Answer: D Ques: 58 Given: 1. public String toString { return Integer. C. Answer: AD Ques: 59 Click the Exhibit button. public void addPlayer(Player p) { 3. D. static void changePayload(Payload p) { 20. super(name.commission = commission. 18. } 5.LinkedList { 2. } 15. class Player { /* more code here */ } Which two are true? (Choose two. C. B.commission = commission. 11. public Payload(int wt) { weight = wt. D. this.commission = commission. superb().util. A Java programmer using the Team class could remove Player objects from a Team object.) A. add(p). } 7. } 16. 13. } 13. public void setWeight(mt w) { weight = w. this. baseSalary). baseSalary).

p = new Payload(420). 26. Which statement(s) are true? (Choose all that apply.println("Clidder"). 25.out. Has-a relationships always rely on instance variables.setWeight(420). B. p = Payload. Has-a relationships always rely on inheritance. 28. Has-a relationships are always tightly coupled.flipper().out. } 29.setWeight(420). p. p.changePayload(420). p. } public static void main(String [] args) { new Clidlets(). Payload p = new Payload(). placed at line 20. p = new Payload(). Flip a Clidlet .setWeight(420).println("Flip a Clidlet"). Answer: -> B is correct. E is incorrect because while has-a relationships can lead to tight coupling. System. } } What is the result? A.setWeight(1024). Payload. } } public class Clidlets extends Clidders { public void flipper() { System. Has-a relationships always rely on polymorphism. D.) A. 27.flipper().out. p. super. it is by no means always the case. E. C. causes the code to print “The value of p is 420. changePayload(p). -> A and D describe other OO topics. } Which statement.24. Ques: 61.”? A. C is incorrect because a class can have an instance of itself. D.setWeight(420). C. B. Has-a relationships always require at least two class types.println(”The value of p is “+ p). Given: class Clidders { public final void flipper() { System. F. E. Answer: A Ques: 60.

B. Answer: -> E is correct. } public static void main(String [] args) { new Bottom2("C"). Ques: 63. public abstract class Frob implements Frobnicate { } C. -> A is incorrect because abstract methods have no body. Compilation fails.) A. final methods cannot be overridden. C.out. C is incorrect because classes implement interfaces they don’t extend them. Flip a Clidlet Flip a Clidder E. public class Frob implements Frobnicate { public void twiddle(Integer i) { } } E.print("B"). public class Frob extends Frobnicate { public void twiddle(Integer i) { } } D. Flip a Clidder C. } Which is a correct class? (Choose all that apply. public abstract class Frob implements Frobnicate { public abstract void twiddle(String s) { } } B. B. Given: public abstract interface Frobnicate { public void twiddle(String s). . } } public class Bottom2 extends Top { public Bottom2(String s) { System. an abstract class need not implement any or all of an interface’s methods. Given: class Top { public Top(String s) { System. the class implements the interface method and additionally overloads the twiddle() method.out. public class Frob implements Frobnicate { public void twiddle(String i) { } public void twiddle(Integer s) { } } Answer: ->B is correct. and D are incorrect based on the above. Ques: 62. D is incorrect because overloading a method is not implementing it.print("D"). E is correct. ->A. Flip a Clidder Flip a Clidlet D.

BDC D. The reference variable is declared for an interface type. It is unlikely that changes made to one class will require any changes in another. B. C and D are incorrect based on the preceding treatise. and all are used.println(" "). Answer: -> E and F are correct. but if each object has many methods. (Choose two. . E. Given: class Clidder { private final void flipper() { System. Stating that changes in one part of a program are unlikely to cause consequences in another part is really the essence of low coupling. not directly. } public static void main(String [] args) { new Clidlet().println("Clidder"). not a class.out. Select the two statements that best indicate a situation with low coupling.flipper(). There is no such thing as an anonymous variable. } } public class Clidlet extends Clidder { public final void flipper() { System. no-arg constructor is generated by the compiler only if the class has no constructor defined explicitly. it may be argued that there is even less opportunity for coupling as the class type itself is not visible. F. The implied super() call in Bottom2’s constructor cannot be satisfied because there isn’t a no-arg constructor in Top.System. Only having access to a small number of methods implies limited coupling. A default. }} What is the result? A. The attributes of the class are all private. -> A. C.out. The class refers to a small number of other objects. If the access is via a reference of interface type. but this describes encapsulation. Answer: -> E is correct. The interface provides a small number of methods. BD B. The object contains only a small number of variables.out.) A. and D are incorrect based on the above. Referring to only a small number of other objects might imply low coupling. Of course. good encapsulation tends to reduce coupling as a consequence. D. -> A. B.println("Clidlet"). Ques: 64. DB C. B. rather than low coupling. Variables (attributes) in a class should usually be private. Compilation fails. then coupling is high. C. The object is referred to using an anonymous variable. Ques: 65. DBC E.

} 4. } Answer: -> A.. 3. Zing is-a Woop and has-a Hmpf. } 5. Answer: -> A is correct.) A. Given: 1. i. the method is private. The effect is that a new. -> B. Clidlet Clidder E.e. class Zing { 2. } D. ->B is incorrect.) A. Ques: 66. will compile? (Choose all that apply. inserted at line 6. } 3. } 8. class Hmpf { } Which is true? (Choose all that apply. Clidder Clidlet D. Plant getType() { return this. // insert code here 7. String getType() { return "this". Flower and Tulip are both subtypes of Plant. Tulip getType() { return new Tulip(). accessible. } B. method flipper is created. A and D are examples of co-variant returns. Clidlet B. String is not a subtype of Plant. in this case. class Woop extends Zing { } 5. C. Woop has-a Hmpf and Woop is-a Zing. Plant getType() { return this. protected Hmpf h. Woop is-a Hmpf and has-a Zing. and therefore hidden. B. Given: 1. and E are incorrect based on the preceding. } 4. Therefore.}} What is the result? A. Clidder C. class Plant { 2. class Flower extends Plant { 6. Although a final method cannot be overridden. Ques: 67. . C. D. and D are correct. Flower getType() { return this. and no error occurs. class Tulip extends Flower { } Which statement(s). D. Compilation fails. no polymorphism occurs in this example. Hmpf has-a Woop and Woop is-a Zing. the method invoked is simply that of the child class. C. String getName() { return "plant". } C.

They are illegal overrides because their return types are incompatible. Ques: 68. Ques: 69. A and B are examples of overriding. Programmer debug() { return this. } B. } } class Minor extends Uber { Minor() { super(y). They are illegal overloads because their arguments did not change. Minor’s constructor makes an explicit call to Uber’s 1-arg constructor. E. Answer: -> D is correct. Given: 1. B is an example of overriding using a covariant return. Object debug(int x) { return this. } E. F. which increments y. specifically. } D. } Uber() { y++. An exception is thrown. y = y + 3. C. int debug() { return 1. // insert code here 6. class Programmer { 2. Object debug() { return this. E and F are examples of overloading.) A. -> C and D are incorrect. inserted at line 5. which makes an explicit (this) call to Uber’s no-arg constructor. class SCJP extends Programmer { 5. Uber(int x) { this(). . } F. 7 C. 6 B. will compile? (Choose all that apply. } Which. Zing has-a Hmpf and Zing is-a Woop. 8 D. Woop inherits a Hmpf from Zing. -> A. int debug(int x) { return 1. B. and F are correct. } 3. y = y * 2. } 4. B. Programmer debug() { return this. System. SCJP debug() { return this. Given: class Uber { static int y = 2. Answer: -> D is correct. and E are incorrect based on the preceding.E. } C. } public static void main(String [] args) { new Minor(). } Answer: -> A. 9 E. Compilation fails.out. }} What is the result? A.println(y).

A will throw a ClassCastException because dog1 refers to a Dog object. D. Ques: 72. } Which. and F are incorrect based on the preceding. 7. -> C and D are incorrect based on the preceding. Given the following. which multiples y * 2. public static void main(String [] args) { 6.) A. Cohesion is the OO principle most closely associated with allowing a single object to be seen as having many types. Beagle b4 = dog2. Beagle b1 = new Beagle(). will compile? (Choose all that apply. class Dog { } 2. -> A refers to encapsulation. C. C. None of the above statements will compile Answer: -> A and B are correct. Answer: -> Answer C is correct. Beagle b3 = (Beagle) dog2. B. Ques: 70. and D refers to polymorphism. 4. Cohesion is the OO principle most closely associated with hiding implementation details. 1. . B. D. inserted at line 9. X x2 = new Y(). well-focused purpose. class Beagle extends Dog { } 3. However. C. 8. at runtime. 9. 4. and then returns to Minor’s constructor. B. Beagle b2 = (Beagle) dog1. Dog dog2 = b1. public static void main(String [] arfs) { 6.) A. class Kennel { 5. Which statement(s) are true? (Choose all that apply. -> A. class X { void do1() { } } 2. X x1 = new X(). 7. Dog dog1 = new Dog(). Cohesion is the OO principle most closely associated with making sure that classes know about other classes only through their APIs. which can’t necessarily do Beagle stuff. B refers to coupling. Ques: 71. Cohesion is the OO principle most closely associated with making sure that a class is designed with a single. } 11. class Chrome { 5. E. Given: 1. which adds 3 to y.then returns to the 1-arg constructor. class Y extends X { void do2() { } } 3. // insert code here 10.

new Hawk(). } public Raptor() { System. B and D are incorrect based on the preceding. pre b2 b1 r2 r3 hawk C. (Y)x2. Static init blocks are executed at class loading time. pre r1 r4 b1 b2 r3 r2 hawk G. pre b1 b2 r3 r2 hawk B. x2. Compilation fails. B. Before you can invoke Y’s do2 method you have to cast x2 to be of type Y.do2(). inserted at line 9.out.do2(). Ques: 73. ((Y)x2). Y y1 = new Y(). r1 r4 pre b2 b1 r2 r3 hawk F. r1 r4 pre b1 b2 r3 r2 hawk E.print("pre "). E. F. and I are incorrect based on the above. } } What is the result? A. G.println("hawk "). } public Bird() { System.8. } static { System.out. // insert code here 10. } Which.out. the compiler thinks it’s an incomplete statement. Statement B looks like a proper cast but without the second set of parentheses. } } class Raptor extends Bird { static { System. B.print("r3 "). H. System.print("b2 ").) A. they run in order. None of the above statements will compile. } { System. Answer: -> D is correct. from the top down. The order of output cannot be predicted.out. pre r1 r4 b2 b1 r2 r3 hawk H.print("r2 "). When multiple init blocks of a single type occur in a class. I. } 11. } } class Hawk extends Raptor { public static void main(String[] args) { System. C. instance init blocks run right after the call to super() in a constructor. C.out. -> A. Given: class Bird { { System. -> A.print("r1 ").do2(). will compile? (Choose all that apply. . 9.out.print("b1 "). pre b2 b1 r2 r3 hawk r1 r4 D. D. Answer: -> C is correct.out.print("r4 ").out.

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->