Ensurepass

 

QUESTION 121

Which two are valid declarations of a two-dimensional array?

 

A.

int [] [] array2D;

B.

int [2] [2] array2D;

C.

int array2D [];

D.

int [] array2D [];

E.

int [] [] array2D [];

 

Correct Answer:
AD

Explanation:

int[][] array2D; is the standard convention to declare a 2-dimensional integer array.

int[] array2D[]; works as well, but it is not recommended.

 

 

QUESTION 122

Given the code fragment:

 

clip_image002

 

Which code fragment prints blue, cyan?

 

clip_image003

 

A.

Option A

B.

Option B

C.

Option C

D.

Option D

 

Correct Answer: A

 

 

QUESTION 123

An unchecked exception occurs in a method dosomething()

 

Should other code be added in the dosomething() method for it to compile and execute?

 

A.

The Exception must be caught

B.

The Exception must be declared to be thrown.

C.

The Exception must be caught or declared to be thrown.

D.

No other code needs to be added.

 

Correct Answer: D

Explanation:

Because the Java programming language does not require methods to catch or to specify unchecked exceptions (RuntimeException,Error, and their subclasses), programmers may be tempted to write code that throws only unchecked exceptions or to make all their exceptionsubclasses inherit fromRuntimeException. Both of these shortcuts allow programmers to write code without bothering with compiler errors and without bothering to specify or to catch anyexceptions. Although this may seem convenient to the programmer, it sidesteps theintent of thecatchorspecifyrequirement and can cause problems for others using your classes.

 

 

QUESTION 124

Given:

 

clip_image005

 

What is the result?

 

A.

hEllOjAvA!

B.

Hello java!

C.

Out of limits

hEllOjAvA!

D.

Out of limits

 

Correct Answer: C

 

 

QUESTION 125

Given the code fragment:

 

System.out.printIn (“Result: ” +3+5);

 

System.out.printIn (“Result: ” + (3+5));

 

What is the result?

 

A.

Result: 8

Result: 8

B.

Result: 35

Result: 8

C.

Result: 8

Result: 35

D.

Result: 35

Result: 35

 

Correct Answer: B

Explanation:

In the first statement 3 and 5 are treated as strings andare simply concatenated. In the first statement 3 and 5 are treated as integers and their sum is calculated.

 

 

QUESTION 126

Given:

 

public class String1 {

 

public static void main(String[] args) {

 

String s = “123”;

 

if (s.length() >2)

 

s.concat(“456”);

 

for(int x = 0; x <3; x++)

 

s += “x”;

 

System.out.println(s);

 

}

 

}

 

What is the result?

 

A.

123

B.

123xxx

C.

123456

D.

123456xxx

E.

Compilation fails

 

Correct Answer: B

Explanation:

123xxx

 

The if clause is not applied.

 

Note: Syntax of if-statement:

if ( Statement ) {

}

 

 

 

 

 

 

 

 

 

 

QUESTION 127

Given the fragment:

 

String[][] arra = new String[3][];

 

arra[0] = new String[]{“rose”, “lily”};

 

arra[1] = new String[]{“apple”, “berry”,”cherry”,”grapes”};

 

arra[0] = new String[]{“beans”, “carrot”,”potato”};

 

// insert code fragment here

 

Which code fragment when inserted at line ‘// insert code fragment here’, enables thecode to successfully change arra elements to uppercase?

 

A.

String[][] arra = new String[3][];

arra[0] = new String[]{“rose”, “lily”};

arra[1] = new String[]{“apple”, “berry”,”cherry”,”grapes”};

arra[0] = new String[]{“beans”, “carrot”,”potato”};

for (int i = 0; i < arra.length; i++) {

for (int j=0; j < arra[i].length; j++) {

arra[i][j] = arra[i][j].toUpperCase();

}

}

B.

for (int i = 0; i < 3; i++) {

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

arra[i][j] = arra[i][j].toUpperCase();

}

}

C.

for (String a[]:arra[][]) {

for (String x:a[]) {

D.

toUpperCase();

}

}

E.

for (int i:arra.length) {

for (String x:arra) {

arra[i].toUpperCase();

}

}

 

Correct Answer: C

Explanation:

Incorrect:

not A: arra.length is 3, but the subarrays have 2, 3 and 4 elements. Index will be out of bound.

not B: The subarrys are of different lengths. Indexwill be out of bound.

not D: Compile error.

 

 

 

 

 

 

 

 

QUESTION 128

Given the code fragment:

 

clip_image006

 

Which code fragment, when inserted at // insert code here, enables the code to compile and and print a b c?

 

A.

List update (String[] strs)

B.

Static ArrayListupdate(String [] strs)

C.

Static List update (String [] strs)

D.

Static void update (String[] strs)

E.

ArrayList static update(String [] strs)

 

Correct Answer: E

 

 

QUESTION 129

Given:

 

public class Main {

 

public static void main(String[] args) {

 

try {

 

doSomething();

 

}

 

catch (SpecialException e) {

 

System.out.println(e);

 

}}

 

static void doSomething() {

 

int [] ages = new int[4];

 

ages[4] = 17;

 

doSomethingElse();

 

}

 

static void doSomethingElse() {

 

throw new SpecialException(“Thrown at end of doSomething() method”); }

 

}

 

What is the output?

 

A.

SpecialException: Thrown at end of doSomething() method

B.

Error in thread “main” java.lang.

ArrayIndexOutOfBoundseror

C.

Exception inthread “main” java.lang.ArrayIndexOutOfBoundsException: 4

at Main.doSomething(Main.java:12)

at Main.main(Main.java:4)

D.

SpecialException: Thrown at end of doSomething() method

at Main.doSomethingElse(Main.java:16)

at Main.doSomething(Main.java:13)

at Main.main(Main.java:4)

 

Correct Answer: C

Explanation:

The following line causes a runtime exception (as the index is out of bounds):

ages[4] = 17;

 

A runtime exception is thrown as anArrayIndexOutOfBoundsException.

 

Note: The third kind of exception (compared to checked exceptions and errors) is the runtime exception. These are exceptional conditions that are internal to the application, and that the application usually cannot anticipate or recover from. These usually indicate programming bugs, such as logic errorsor improper use of an API. Runtime exceptionsare not subjectto the Catch or Specify Requirement. Runtime exceptions are those indicated byRuntimeExceptionand its subclasses.

 

 

 

 

 

 

 

 

 

 

 

 

QUESTION 130

Given:

 

clip_image008

 

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

 

Correct Answer: A

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.