Q1. Given a code fragment:
A. They match They real match
B. They really match
C. They match
D. Nothing is printed to the screen
Answer: B
Q2. Given:
What is the result?
A. One
B. Two
C. Three
D. Compilation fails
Answer: C
Q3. 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: C
Q4. Given the code fragment:
Answer:
Q5. Which is a valid abstract class?
A. public abstract class Car {
protected void accelerate();
}
B. public interface Car {
protected abstract void accelerate();
}
C. public abstract class Car {
protected final void accelerate();
}
D. public abstract class Car {
protected abstract void accelerate();
}
E. public abstract class Car {
protected abstract void accelerate() {
//more car can do
}}
Answer: D
Q6. Given:
What is the result?
A. x: 1 y: 2
B. 3 y: 4
C. x: 0 y: 0
D. 3 y: 4
E. x: 1 y: 2
F. 0 y: 0
G. x: 0 y: 0
H. 0 y: 0
Answer: C
Q7. What is the result?
A. 6 7 8
B. 7 8 9
C. 0 1 2
D. 6 8 10
E. Compilation fails
Answer: A
Q8. Given:
What is the result?
A. The sum is 2
B. The sum is 14
C. The sum is 15
D. The loop executes infinite times
E. Compilation fails
Answer: D
Q9. Given:
What is the result?
A. Marrown
String out of limits
JesOran
B. Marrown
String out of limits
Array out of limits
C. Marrown
String out of limits
D. Marrown
NanRed
JesOran
Answer: D
Q10. Given:
Which two actions, used independently, will permit this class to compile?
A. Adding throws IOException to the main() method signature
B. Adding throws IOException to the doSoomething() method signature
C. Adding throws IOException to the main() method signature and to the dosomething() method
D. Adding throws IOException to the dosomething() method signature and changing the catch argument to IOException
E. Adding throws IOException to the main() method signature and changing the catch argument to IOException
Answer: CD
Q11. Given:
What is the result?
A. Null
B. Compilation fails
C. An exception is thrown at runtime
D. 0
Answer: A
Q12. Given:
Given the code fragment:
What is the result?
A. 10 20 30 40
B. 0 0 30 40
C. Compilation fails
D. An exception is thrown at runtime
Answer: A
Q13. Given:
Which two modifications are necessary to ensure that the class is being properly encapsulated?
The class is poorly encapsulated. You need to change the circle class to compute and return the area instead.
A. Remove the area field.
B. Change the getArea( ) method as follows: public double getArea ( ) { return Match.PI * radius * radius; }
C. Add the following method: public double getArea ( ) {area = Match.PI * radius * radius; }
D. Change the cacess modifier of the SerRadius ( ) method to be protected.
Answer: BD
Q14. which three lines are illegal?
A. line 3
B. line 4
C. line 5
D. line 6
E. line 10
F. line 11
G. line 12
H. line 13
Answer: CDH
Q15. Given:
What is the result?
A. 1 1 1
B. 1 2 3
C. 2 3 4
D. Compilation fails
E. The loop executes infinite times
Answer: D
Q16. Given the code fragment:
String h1 = "Bob";
String h2 = new String ("Bob");
What is the best way to test that the values of h1 and h2 are the same?
A. if (h1 = = h2)
B. if (h1.equals(h2))
C. if (h1 = = h2)
D. if (h1.same(h2))
Answer: B