Q1. Which two statements are true?
C. An interface CANNOT be extended by another interface.
D. An interface can be extended by an abstract class.
E. An abstract class can be extended by a concrete class.
F. An abstract class CANNOT be extended by an abstract class.
Answer: AE
Q2. boolean log3 = ( 5.0 != 6.0) && ( 4 != 5);
boolean log4 = (4 != 4) || (4 == 4);
System.out.println("log3:"+ log3 + \nlog4" + log4);
What is the result?
A. log3:false log4:true
B. log3:true log4:true
C. log3:true log4:false
D. log3:false log4:false
Answer: B
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:
Which two declarations will compile?
A. int a, b, c = 0;
B. int a, b, c;
C. int g, int h, int i = 0;
D. int d, e, F;
E. int k, l, m; = 0;
Answer: AD
Q5. Given:
What is the result?
A. One
B. Two
C. Three
D. Compilation fails
Answer: C
Q6. Given the code fragment:
Answer:
Q7. Given the code fragment:
A. Super Sub Sub
B. Contract Contract Super
C. Compilation fails at line n1
D. Compilation fails at line n2
Answer: D
Q8. Given:
What is the result?
A. Option A
B. Option B
C. Option C
D. Option D
Answer: C
Q9. View the exhibit:
public class Student {
public String name = "";
public int age = 0;
public String major = "Undeclared";
public boolean fulltime = true;
public void display() {
System.out.println("Name: " + name + " Major: " + major); }
public boolean isFullTime() {
return fulltime;
}
}
Given:
Public class TestStudent {
public static void main(String[] args) {
Student bob = new Student ();
bob.name = "Bob";
bob.age = 18;
bob.year = 1982;
}
}
What is the result?
A. year is set to 1982.
B. bob.year is set to 1982
C. A runtime error is generated.
D. A compile time error is generated.
Answer: D
Q10. Which two are valid declarations of a two-dimensional array?
A. int [] [] array2D;
B. int [2] [2] array2D;
C. int array2D [];
D. int [] array2D [];
E. int [] [] array2D [];
Answer: AD