9. Consider the following code.
int x = 2;
switch (x) {
case 1: x += 3;
case 2: x += 5;
case 3: x += 7;
default: x += 10;
}
Which syntax correctly prints an array?
for (int n = 1; n <= x.length; n++) {
System.out.println(x[n]);
}
for (int n=0; n <= x.length; n++) {
System.out.println(x[n]);
}
for (int n = 1; n < x.length; n++) {
System.out.println(x[n]);
}
for (int n=0; n < x.length; n++) {
System.out.println(x[n]);
}
10. Consider the following declaration.
int[] two = {{1,2,3}, {4,5}};
Which arithmetic expression evaluates to a value of 8?
two[3] + two[2]
two[2] + two[1]
two[1][3] + two[2][2]
two[0][2] + two[1][1]
11. Consider the following method.
public static void print (int a, int b) {
System.out.println("The sum is " + (a + b));
}
If the print method is in the same class as the main method and there are no other methods named print, which of the following statements, called from the main method, will not cause a compiler error?
System.out.println(print(2,3));
System.out.println(print(2 + 3));
print(2, 3);
print(2 + 3);

12. Which of the following expressions correctly and most accurately calculates the area of a circle with radius r?
Math.pow(r, 2) * Math.PI
Math.power(r,2) * Math.PI
Math.pow(2, r) * Math.PI
Math.exp(r, 2) * Math.PI
13. Consider the following code.
public class Amazing {
int x;
int y;
}
Which of the following shows a statement that will create an instance of class Amazing and assign its reference to a reference variable?
Amazing a = new Amazing;
Amazing a = new Amazing();
Amazing a = Amazing();
It is not possible to create an instance of class Amazing. It does not have a constructor.
14. Consider the following code.
public class Employee {
private String firstName;
private String lastName;
private int empId;
}
Which of the following shows a constructor that, if added to class Employee, would allow a caller to create an object and pass in values that will be assigned to its instance variables?
public Employee() {
firstName = "Fred";
lastName = "Jones";
empId = 101;
}
public Employee(String a, String b, int c) {
firstName = a;
lastName = b;
empId = c;
}
public Employee("Fred", "Jones", 101) {
firstName = a;
lastName = b;
empId = c;
}
public Employee(String a, String b, int c) {
firstName = "Fred";
lastName = "Jones";
empId = 101;
}
15. What is the output of the following code?
String name1 = "Chris";
String name2 = "Christine";
boolean b = name1.startsWith(name2);
boolean c = name1.charAt(4) == name2.charAt(7);
System.out.println(b + ", " + c);
true, true
true, false
false, true
false, false

Respuesta :

9. x is an integer, not an array. None of those System.out() work.
10. two[0][2] + two[1][1]
11. print(2, 3);
12. Math.pow(r, 2) * Math.PI
13. I'm not sure
14. public Employee(String a, String b, int c) {
firstName = a;
lastName = b;
empId = c;
}
15. false, false