Q1. Given:
What is the result?
A. 11, 21, 31, 11, 21, 31
B. 11, 21, 31, 12, 22, 32
C. 12, 22, 32, 12, 22, 32
D. 10, 20, 30, 10, 20, 30
Answer: D
Q2. Given:
What is the result?
A. true true
B. true false
C. false true
D. false false
E. Compilation fails
Answer: E
Q3. What is the result?
A. Hello
B. Default
C. Compilation fails
D. The program prints nothing
E. An exception is thrown at run time
Answer: A
Q4. Given:
What will be the output?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: D
Q5. Given:
What is the result?
A. Shining Sun
Shining Sun
Shining Sun
B. Shining Sun
Twinkling Star
Shining Sun
C. Compilation fails
D. A ClassCastException is thrown at runtime
Answer: D
Q6. Class StaticField {
static int i = 7;
public static void main(String[] args) {
StaticFied obj = new StaticField();
obj.i++;
StaticField.i++;
obj.i++;
System.out.println(StaticField.i + " "+ obj.i);
}
}
What is the result?
A. 10 10
B. 8 9
C. 9 8
D. 7 10
Answer: A
Q7. Given:
class X {}
class Y { Y ( ) { } }
class Z { Z (int i ) { } }
Which class has a default constructor?
A. X only
B. Y only
C. Z only
D. X and Y
E. Y and Z
F. X and Z
G. X, Y and Z
Answer: A
Q8. Which code fragment, when inserted at line 9, enables the code to print true?
A. String str2 = str1;
B. String str2 = new string (str1);
C. String str2 = sb1.toString();
D. String str2 = “Duke”;
Answer: B
Q9. Which code fragment cause a compilation error?
A. flat flt = 100F;
B. float flt = (float) 1_11.00;
C. float flt = 100;
D. double y1 = 203.22; floatflt = y1
E. int y2 = 100; floatflt = (float) y2;
Answer: B
Q10. Given:
What is the result?
A. Compilation fails
B. The code compiles, but does not execute.
C. Paildrome
D. Wow
E. Mom
Answer: B
Q11. Given:
What is the result?
A. One
B. Two
C. Three
D. Compilation fails
Answer: D
Q12. Given:
What should statement1, statement2, and statement3, be respectively, in order to produce the result?
Shape: constructor
Square: foo
Shape: foo
A. Option A
B. Option B
C. Option C
D. Option D
E. Option E
Answer: D
Q13. Given the code fragment:
String name = "Spot";
int age = 4;
String str ="My dog " + name + " is " + age;
System.out.println(str);
And
StringBuilder sb = new StringBuilder();
Using StringBuilder, which code fragment is the best potion to build and print the following
string My dog Spot is 4
A. sb.append("My dog " + name + " is " + age); System.out.println(sb);
B. sb.insert("My dog ").append( name + " is " + age); System.out.println(sb);
C. sb.insert("My dog ").insert( name ).insert(" is " ).insert(age); System.out.println(sb);
D. sb.append("My dog ").append( name ).append(" is " ).append(age);
System.out.println(sb);
Answer: AD
Q14. You are writing a method that is declared not to return a value. Which two are permitted in
the method body?
A. omission of the return statement
B. return null;
C. return void;
D. return;
Answer: AD
Q15. Given:
What code should be inserted?
A. Option A
B. Option B
C. Option C
D. Option D
E. Option E
F. Option F
Answer: C
Q16. Which code fragments, inserted independently, enable the code compile?
A. t.fvar = 200;
B. cvar = 400;
C. fvar = 200; cvar = 400;
D. this.fvar = 200; this.cvar = 400;
E. t.fvar = 200; Test2.cvar = 400;
F. this.fvar = 200; Test2.cvar = 400;
Answer: B