8. public int getNumber (int a) { 9. return a + 2 10. } 11.
12. public static void main (String args[]) { 13. A a = new B();
14. System.out.printIn(a.getNumber(0)); 15. } 16. }
What is the result?
A. Compilation succeeds and 1 is printed. B. Compilation succeeds and 2 is printed.
C. An error at line 8 causes compilation to fail. D. An error at line 13 causes compilation to fail. E. An error at line 14 causes compilation to fail. Answer: B
QUESTION NO: 69 Given:
1. class BaseClass{ 2. private float x= 1.0f;
3. protected void setVar (float f) {x = f;} 4. }
5. class SubClass exyends BaseClass { 6. private float x = 2.0f; 7. //insert code here 8. }
Which two are valid examples of method overriding? (Choose Two) A. Void setVar(float f) {x = f;} B. Public void setVar(int f) {x = f;} C. Public void setVar(float f) {x = f;} D. Public double setVar(float f) {x = f;} E. Public final void setVar(float f) {x = f;}
F. Protected float setVar() {x=3.0f; return 3.0f; } Answer: C, E
QUESTION NO: 70
Which statement about static inner classes is true? A. An anonymous class can be declared as static.
B. A static inner class cannot be a static member of the outer class.
C. A static inner class does not require an instance of the enclosing class.
D. Instance members of a static inner class can be referenced using the class name of the static inner class.
Answer: C
QUESTION NO: 71 Exhibit: 1. class A {
2. public byte getNumber () { 3. return 1; 4. } 5. } 6.
7. class B extends A {
8. public short getNumber() { 9. return 2; 10. } 11.
12. public static void main (String args[]) { 13. B b = new B ();
14. System.out.printIn(b.getNumber()) 15. } 16. }
What is the result?
A. Compilation succeeds and 1 is printed. B. Compilation succeeds and 2 is printed.
C. An error at line 8 causes compilation to fail. D. An error at line 14 causes compilation to fail.
E. Compilation succeeds but an exception is thrown at line 14. Answer: C
QUESTION NO: 72 Given:
AnInterface is an interface.
AnAdapter0 is a non-abstract, non-final class with a zero argument constructor.
AnAdapter1 is a non-abstract, non-final class without a zero argument constructor, but with a constructor that
takes one int argument.
Which two construct an anonymous inner class? (Choose Two) F. AnAdapter1 aa=new AnAdapter1(){} G. AnAdapter0 aa=new AnAdapter0(){} H. AnAdapter0 aa=new AnAdapter0(5){} I. AnAdapter1 aa=new AnAdapter1(5){} J. AnInterface a1=new AnInterface(5){} Answer: B, D
QUESTION NO: 73
Which two statements are true? (Choose Two) A. An inner class may be declared as static.
B. An anonymous inner class can be declared as public. C. An anonymous inner class can be declared as private.
D. An anonymous inner class can extend an abstract class. E. An anonymous inner class can be declared as protected. Answer: A, D
QUESTION NO: 74 Exhibit:
1. public class Mycircle { 2. public double radius; 3. public double diameter; 4.
5. public void setRadius(double radius) 6. this.radius = radius;
7. this.diameter= radius * 2; 8. } 9.
10. public double getRadius() { 11. return radius; 12. } 13. }
Which statement is true?
A. The Mycircle class is fully encapsulated.
B. The diameter of a given MyCircle is guaranteed to be twice its radius. C. Lines 6 and 7 should be in a synchronized block to ensure encapsulation. D. The radius of a MyCircle object can be set without affecting its diameter. Answer: B
QUESTION NO: 75
You want to limit access to a method of a public class to members of the same class. Which access modifier accomplishes this objective? A. Public B. Private C. Protected D. Transient
E. No access modifier is required Answer: B
QUESTION NO: 76 Exhibit:
ClassOne.java
1. package com.abc.pkg1; 2. public class ClassOne { 3. private char var = ?a';
4. char getVar() {return var;} 5. }
ClassTest.java
1. package com.abc.pkg2;
2. import com.abc.pkg1.ClassOne;
3. public class ClassTest extends ClassOne { 4. public static void main(String[]args) { 5. char a = new ClassOne().getVar(); 6. char b = new ClassTest().getVar(); 7. } 8. }
What is the result?
A. Compilation will fail.
B. Compilation succeeds and no exceptions are thrown.
C. Compilation succeeds but an exception is thrown at line 5 in ClassTest.java. D. Compilation succeeds but an exception is thrown at line 6 in ClassTest.java. Answer: B
QUESTION NO: 77 Given:
1. public class ArrayTest {
2. public static void main (String[]args) { 3. float f1[], f2[]; 4. f1 = new float [10]; 5. f2 = f1;
6. System.out.printIn (“f2[0]=” + f2[0]); 7. } 8. }
What is the result? A. It prints f2[0] = 0.0 B. It prints f2[0] = NaN
C. An error at line 5 causes compile to fail. D. An error at line 6 causes compile to fail.
E. An error at line 6 causes an exception at runtime. Answer: A
QUESTION NO: 78
Which two statements are true regarding the creation of a default constructor? (Choose Two) A. The default constructor initializes method variables.
B. The compiler always creates a default constructor for every class.
C. The default constructor invokes the no-parameter constructor of the superclass. D. The default constructor initializes the instance variables declared in the class.
E. When a class has only constructors with parameters, the compiler does not create a default constructor. Answer: D, E
QUESTION NO: 79 Exhibit:
1. class super {
2. public int getLength() {return 4;} 3. } 4.
5. public class Sub extends Super { 6. public long getLength() {return 5;} 7.
8. public static void main (String[]args) { 9. super sooper = new Super (); 10. Sub sub = new Sub(); 11. System.out.printIn(
12. sooper.getLength()+ “,” + sub.getLength() }; 13. } 14. }
What is the output? A. 4, 4 B. 4, 5 C. 5, 4 D. 5, 5
E. The code will not compile. Answer: E
QUESTION NO: 80 Given:
1. public abstract class Test {
2. public abstract void methodA(); 3.
4. public abstract void methodB() 5. {
6. System.out.printIn(“Hello”); 7. } 8. }
Which three changes (made independently) allow the code to compile? (Choose Three) A. Add a method body to methodA.
B. Replace lines 5-7 with a semicolon (“.”)
C. Remove the abstract qualifier from the declaration of Test.
D. Remove the abstract qualifier from the declaration of methodB. E. Remove the abstract qualifier from the declaration of methodA.
F. Remove methodB in its entirely and change class o interface in line 1. Answer: B, D, F
QUESTION NO: 81
Which determines if “prefs” is a directory and exists on the file system? A. Boolean exists=Directory.exists (“prefs”); B. Boolean exists=(new File(“prefs”)).isDir();
C. Boolean exists=(new Directory(“prefs”)).exists(); D. Boolean exists=(new File(“prefs”)).isDirectory(); E. Boolean exists=true; Try{