0% found this document useful (0 votes)
46 views

DURGA's SCJP Material: DURGASOFT, # 202,2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038, 040 - 64 51 27 86

The document contains questions and answers related to Java programming concepts like classes, inheritance, and encapsulation. Specifically: - Question 12 asks about the output of a program with a Base class and Sub class that extends Base. The answer is that the output would be "foobarfoobarfoo". - Question 13 asks which two statements are true about encapsulation. The answers are that an encapsulated, public class promotes re-use, and an encapsulated class allows changing an implementation without affecting outside code.

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)
46 views

DURGA's SCJP Material: DURGASOFT, # 202,2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038, 040 - 64 51 27 86

The document contains questions and answers related to Java programming concepts like classes, inheritance, and encapsulation. Specifically: - Question 12 asks about the output of a program with a Base class and Sub class that extends Base. The answer is that the output would be "foobarfoobarfoo". - Question 13 asks which two statements are true about encapsulation. The answers are that an encapsulated, public class promotes re-use, and an encapsulated class allows changing an implementation without affecting outside code.

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

C. Compilation fails because of an error in line 9.


D. If you define D e = new E(), then e.bMethod() invokes the version of bMethod()
defined in Line 5.
E. If you define D e = (D)(new E()), then e.bMethod() invokes the version of bMethod()
defined in Line 5.
F. If you define D e = (D)(new E()), then e.bMethod() invokes the version of bMethod()
defined in Line 9.

Answer: F

Q: 12 Given:
1. public class Base {
2. public static final String FOO = "foo";
3. public static void main(String[] args) {
4. Base b = new Base();
5. Sub s = new Sub();
6. System.out.print(Base.FOO);
7. System.out.print(Sub.FOO);
8. System.out.print(b.FOO);
9. System.out.print(s.FOO);
10. System.out.print(((Base)s).FOO);
11. } }
12. class Sub extends Base {public static final String FOO="bar";}

What is the result?


A. foofoofoofoofoo
B. foobarfoobarbar
C. foobarfoofoofoo
D. foobarfoobarfoo
E. barbarbarbarbar
F. foofoofoobarbar
G. foofoofoobarfoo

Answer: D

Q: 13 Which two statements are true? (Choose two.)


A. An encapsulated, public class promotes re-use.
B. Classes that share the same interface are always tightly encapsulated.
C. An encapsulated class allows subclasses to overload methods, but does NOT allow overriding
methods.
D. An encapsulated class allows a programmer to change an implementation without affecting outside
code.
Answer: A, D

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


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

You might also like