0% found this document useful (0 votes)
16 views1 page

Durga'S SCJP Material: A. P0 P1 B. P1 P2 C. P2 P4 D. P2 (Classc) P1 E. P1 (Classb) P3 F. P2 (Classc) P4

This document provides sample questions and answers from a SCJP exam preparation material. The first question asks which code assignments are valid given classes ClassA, ClassB, and ClassC. The valid assignments are p0 = p1, which assigns an object of ClassA to another ClassA variable, p1 = (ClassB)p3, which casts the ClassA object to a ClassB, and p2 = (ClassC)p4, which casts the ClassA object to a ClassC. The second question defines classes Vehicle, Car, and RaceCar in a hierarchy and creates objects of each. It then calls the speed method on each object and prints the results. The printed output would be

Uploaded by

ROHIT JAIN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views1 page

Durga'S SCJP Material: A. P0 P1 B. P1 P2 C. P2 P4 D. P2 (Classc) P1 E. P1 (Classb) P3 F. P2 (Classc) P4

This document provides sample questions and answers from a SCJP exam preparation material. The first question asks which code assignments are valid given classes ClassA, ClassB, and ClassC. The valid assignments are p0 = p1, which assigns an object of ClassA to another ClassA variable, p1 = (ClassB)p3, which casts the ClassA object to a ClassB, and p2 = (ClassC)p4, which casts the ClassA object to a ClassC. The second question defines classes Vehicle, Car, and RaceCar in a hierarchy and creates objects of each. It then calls the speed method on each object and prints the results. The printed output would be

Uploaded by

ROHIT JAIN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

DURGA’s SCJP Material

and:
21. ClassA p0 = new ClassA();
22. ClassB p1 = new ClassB();
23. ClassC p2 = new ClassC();
24. ClassA p3 = new ClassB();
25. ClassA p4 = new ClassC();
Which three are valid? (Choose three.)
A. p0 = p1;
B. p1 = p2;
C. p2 = p4;
D. p2 = (ClassC)p1;
E. p1 = (ClassB)p3;
F. p2 = (ClassC)p4;
Answer: A, E, F

Q: 49 Given:
11. abstract class Vehicle { public int speed() { return 0; }
12. class Car extends Vehicle { public int speed() { return 60; }
13. class RaceCar extends Car { public int speed() { return 150; }
...
21. RaceCar racer = new RaceCar();
22. Car car = new RaceCar();
23. Vehicle vehicle = new RaceCar();
24. System.out.println(racer.speed() + ", " + car.speed()
25. + ", " + vehicle.speed());
What is the result?
A. 0, 0, 0
B. 150, 60, 0
C. Compilation fails.
D. 150, 150, 150
E. An exception is thrown at runtime.

Answer: D

Q: 50 Given code in separate source files:

10. public class Foo {


11. public int a;
12. public Foo() { a = 3; }
13. public void addFive() { a += 5;}
14. } and: 20. public class Bar extends Foo {
21. public int a;
22. public Bar() { a = 8; }
23. public void addFive() { this.a += 5; }
24. } invoked with:
30. Foo foo = new Bar();
31. foo.addFive();
32. System.out.println("Value: " + foo.a);
What is the result?

DURGASOFT, # 202,2nd Floor,HUDA Maitrivanam,Ameerpet, Hyderabad - 500038,  040 – 64 51 27 86,


80 96 96 96 96, 9246212143 | www.durgasoft.com Page 28

You might also like