Ensurepass

QUESTION 71

Given:

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) {

}

}

What is the result?

 A. One B. Two C. Three D. Compilation fails.

QUESTION 72

Given:

class Sports {

int num_players;

String name, ground_condition;

Sports(int np, String sname, String sground){

num_players = np;

name = sname;

ground_condition = sground;

}

}

class Cricket extends Sports {

int num_umpires;

int num_substitutes;

Which code fragment can be inserted at line //insert code here to enable the code to compile?

 A. Cricket() { super(11, “Cricket”, “Condidtion OK”); num_umpires =3; num_substitutes=2; } B. Cricket() { super.ground_condition = “Condition OK”; super.name=”Cricket”; super.num_players = 11; num_umpires =3; num_substitutes=2; } C. Cricket() { this(3,2); super(11, “Cricket”, “Condidtion OK”); } Cricket(int nu, ns) { this.num_umpires =nu; this.num_substitutes=ns; } D. Cricket() { this.num_umpires =3; this.num_substitutes=2; super(11, “Cricket”, “Condidtion OK”); }

Explanation:

Incorrect:

not C, not D: call to super must be the first statement in constructor.

QUESTION 73

Given the code fragment:

What is the result?

 A. 20 B. 25 C. 29 D. Compilation fails E. AnArrayIndexOutOfBoundsException is thrown at runtime

QUESTION 74

A method is declared to take three arguments. A program calls this method and passes only two arguments. What is the result?

 A. Compilation fails. B. The third argument is given the value null. C. The third argument is given the value void. D. The third argument is given the value zero. E. The third argument is given the appropriate false valuefor its declared type. F. An exception occurs when the method attempts to access the third argument.

Explanation:

The problem is noticed at build/compile time. At build you would receive an error message like:

required: int,int,int

found: int,int

QUESTION 75

Given:

public class X {

static int i;

int j;

public static void main(String[] args) {

X x1 = new X();

X x2 = new X();

x1.i = 3;

x1.j = 4;

x2.i = 5;

x2.j = 6;

System.out.println(

x1.i + ” “+

x1.j + ” “+

x2.i + ” “+

x2.j);

}

}

What is the result?

 A. 3 4 5 6 B. 3 4 3 6 C. 5 4 5 6 D. 3 6 4 6

QUESTION 76

Given:

What is the result?

 A. The program prints nothing B. d is output C. A StringIndexOutOfBo undsException is thrown at runtime. D. AnArrayIndexOutOfBoundsException is thrown at runtime. E. A NullPointerException is thrown at runtime.

QUESTION 77

Given:

Which approach ensures that the class can be compiled and run?

 A. Put the throw new Exception() statement in the try block of try ?catch B. Put the doSomethingElse() method in the try block of a try ?catch C. Put the doSomething() method in the try block of a try ?catch D. Put thedoSomething() method and the doSomethingElse() method in the try block of a try ?catch

Explanation:

We need to catch the exception in the doSomethingElse() method.

Such as:

private static void doSomeThingElse() {

try {

throw new Exception();}

catch (Exception e)

{}

}

Note: One alternative, but not an option here, is the declare the exception in doSomeThingElse and catch it in the doSomeThing method.

QUESTION 78

int [] array = {1,2,3,4,5};

for (int i: array) {

if ( i < 2) {

keyword1;

}

System.out.println(i);

if ( i == 3) {

keyword2 ;

}}

What should keyword1 and keyword2 be respectively, in oreder to produce output 2345?

 A. continue, break B. break, break C. break, continue D. continue, continue

QUESTION 79

Which two are Java Exception classes?

 A. SercurityException B. DuplicatePathException C. IllegalArgumentException D. TooManyArgumentsException

QUESTION 80

Given:

What is the result?

 A. 2 4 6 8 B. 2 4 6 8 9 C. 1 3 5 7 D. 1 3 5 7 9