Ensurepass

 

QUESTION 111

Given:

 

clip_image002

 

Why will the code not compile?

 

A.

A static field cannot be private.

B.

The getLetter method has no body.

C.

There is no setLetter method.

D.

The letter field is uninitialized.

E.

It contains a method named Main instead of ma.

 

Correct Answer: B

Explanation:

The getLetter() method needs a body public static int getLetter() { }; .

 

 

QUESTION 112

Given:

 

public class Test {

 

public static void main(String[] args) {

 

int arr[] = new int[4];

 

arr[0] = 1;

 

arr[1] = 2;

 

arr[2] = 4;

 

arr[3] = 5;

 

int sum = 0;

 

try {

 

for (int pos = 0; pos <= 4; pos++) {

 

sum = sum +arr[pos];

 

}

 

} catch (Exception e) {

 

System.out.println(“Invalid index”);

 

}

 

System.out.println(sum);

 

}

 

}

 

What is the result?

 

A.

12

B.

Invalid Index

C.

Invalid Index

D.

Compilation fails

 

Correct Answer: B

Explanation:

The loop ( for (int pos = 0; pos <= 4; pos++) { ), it should be pos <= 3, causes an exception, which is caught. Then the correct sum is printed.

 

 

QUESTION 113

Given:

 

public class DoBreak1 {

 

public static void main(String[] args) {

 

String[] table = {“aa”, “bb”, “cc”, “dd”};

 

for (String ss: table) {

 

if ( “bb”.equals(ss)){

 

continue;

 

}

 

System.out.println(ss);

 

if ( “cc”.equals(ss)) {

 

break;

 

}

 

}

 

}

 

}

 

What is the result?

A.

aa

cc

B.

aa

bb

cc

C.

cc

dd

D.

cc

E.

Compilation fails.

 

Correct Answer: A

 

 

QUESTION 114

Which two are valid instantiations and initializations of a multi dimensional array?

 

clip_image004

 

A.

Option A

B.

Option B

C.

Option C

D.

Option D

E.

Option E

 

Correct Answer: AD

 

 

 

 

 

 

 

 

 

 

QUESTION 115

Given:

 

clip_image006

 

What is the
result?

 

A.

2

B.

2

C.

null

D.

an infinite loop

E.

compilation fails

 

Correct Answer: E

Explanation:

The line while (–ii); will cause the compilation to fail.

ii is not aboolean value.

A correct line would be while (–ii>0);

 

 

QUESTION 116

Given:

 

public class TestLoop {

 

public static void main(String[] args) {

 

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

 

int key = 3;

 

for (int pos = 0; pos < array.length; ++pos) {

 

if (array[pos] == key) {

 

break;

 

}

 

}

 

System.out.print(“Found ” + key + “at ” + pos);

 

}

 

}

What is the result?

 

A.

Found 3 at 2

B.

Found 3 at 3

C.

Compilation fails

D.

An exception is thrown at runtime

 

Correct Answer: C

Explanation:

The following linedoes not compile:

System.out.print(“Found ” + key + “at ” + pos);

The variable pos is undefined at this line, as its scope is only valid in the for loop. Any variables created inside of a loop are LOCAL TO THE LOOP.

 

 

QUESTION 117

Given:

 

clip_image008

 

Which statement, when inserted into line 5, is valid change?

 

A.

asc = sc;

B.

sc = asc;

C.

asc = (object) sc;

D.

asc = sc.clone ()

 

Correct Answer: B

Explanation:

Works fine.

 

 

QUESTION 118

Given:

 

clip_image009

What is the result?

 

A.

Compilation fails

B.

The code compiles, but does not execute.

C.

Paildrome

D.

Wow

E.

Mom

 

Correct Answer: B

 

 

QUESTION 119

Which three are advantages of the Java exception mechanism?

 

A.

Improves the program structure because the error handling code is separated from the normal program function

B.

Provides a set of standard exceptions that covers all thepossible errors

C.

Improves the program structure because the programmer can choose where to handle exceptions

D.

Improves the program structure because exceptions must be handled in the method in which they occurred

E.

allows the creation of new exceptions that are tailored to the particular program being

 

Correct Answer: ACE

Explanation:

A: The error handling is separated from the normal program logic.

C: You have some choice where to handle the exceptions.

E: You can create your own exceptions.

 

 

QUESTION 120

Given:

 

clip_image011

 

What will be the output?

 

clip_image013

 

A.

Option A

B.

Option B

C.

Option C

D.

Option D

 

Correct Answer: D

Free VCE & PDF File for Oracle 1Z0
-803 Real Exam


Instant Access to Free VCE Files: CompTIA | VMware | SAP …
Instant Access to Free PDF Files: CompTIA | VMware | SAP …

 

Comments are closed.