Q11. Which three are bad practices? 

A. Checking for ArrayIndexoutofBoundsException when iterating through an array to determine when all elements have been visited 

B. Checking for Error and. If necessary, restarting the program to ensure that users are unaware problems 

C. Checking for FileNotFoundException to inform a user that a filename entered is not valid 

D. Checking for ArrayIndexoutofBoundsException and ensuring that the program can recover if one occur 

E. Checking for an IOException and ensuring that the program can recover if one occurs 

Answer: ABD 


Q12. 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:


Q13. Given: 

What is the result? 

A. null 

B. compilation fails 

C. Java.lang.NullPointerException 

D. 0 

Answer:


Q14. Given the code fragment: 

What is the result? 

A. 2 2 

B. 1 2 

C. 3 2 

D. 3 3 

Answer:


Q15. What is the result? 

A. Valid 

B. Not valid 

C. Compilation fails 

D. An IllegalArgumentException is thrown at run time 

Answer:


Q16. Given: 

What is the result? 

A. Red 0 

Orange 0 

Green 3 

B. Red 0 

Orange 0 

Green 6 

C. Red 0 

Orange 1 

D. Green 4 

E. Compilation fails 

Answer:


Q17. 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; 

Which line of code initializes a student instance? 

A. Student student1; 

B. Student student1 = Student.new(); 

C. Student student1 = new Student(); 

D. Student student1 = Student(); 

Answer:


Q18. Given: 

What is the result? 

A. Compilation fails 

B. An exception is thrown at runtime 

C. There is no result because this is not correct way to determine the hash code 

D. Hash is: 111111, 44444444, 999999999 

Answer:


Q19. class Overloading { 

int x(double d) { 

System.out.println("one"); 

return 0; 

String x(double d) { 

System.out.println("two"); 

return null; 

double x(double d) { 

System.out.println("three"); 

return 0.0; 

public static void main(String[] args) { 

new Overloading().x(4.0); 

What is the result? 

A. One 

B. Two 

C. Three 

D. Compilation fails. 

Answer:


Q20. Which two actions will improve the encapsulation of a class? 

A. Changing the access modifier of a field from public to private 

B. Removing the public modifier from a class declaration 

C. Changing the return type of a method to void 

D. Returning a copy of the contents of an array or ArrayList instead of a direct reference 

Answer: AD