Ensurepass

 

QUESTION 91

Given:

 

public class ColorTest {

 

public static void main(String[] args) {

 

String[] colors = {“red”, “blue”,”green”,”yellow”,”maroon”,”cyan”};

 

int count = 0;

 

for (String c : colors) {

 

if (count >= 4) {

 

break;

 

}

 

else {

 

continue;

 

}

 

if (c.length() >= 4) {

 

colors[count] = c.substring(0,3);

 

}

 

count++;

 

}

 

System.out.println(colors[count]);

 

}

 

}

 

What is the result?

 

A.

Yellow


B.

Maroon

C.

Compilation fails

D.

A StringIndexOutOfBoundsException is thrown at runtime.

 

Correct Answer: C

Explanation:

Theline, if (c.length() >= 4) {, is never reached. This causes a compilation error.

 

Note: The continue statement skips the current iteration of a for, while , or do-while loop. An unlabeled break statement terminates the innermost switch, for, while, or do- while statement, but a labeled break terminates an outer statement.

QUESTION 92

Given:

 

clip_image002

 

What is the result?

 

A.

There is no output

B.

d is output

C.

A StringIndexOutOfBoundsException is thrown at runtime

D.

An ArrayIndexOutOfBoundsException is thrown at runtime

E.

A NullPointException is thrown at runtime

F.

A StringArrayIndexOutOfBoundsException is thrown at runtime

 

Correct Answer: C

Explanation:

There are only 11 characters in the string “Hello World”. The code theString.charAt(11) retrieves the 12th character, which does not exist. A StringIndexOutOfBoundsException is thrown.

Exception in thread “main” java.lang.StringIndexOutOfBoundsException: String index out of range: 11

 

 

QUESTION 93

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();

 

Correct Answer: C

 

 

QUESTION 94

Given a code fragment:

 

clip_image004

 

What is the result?

 

A.

They match

They real match

B.

They really match

C.

They match

D.

Nothing is printed to the screen

 

Correct Answer: B

 

 

QUESTION 95

int i, j=0;

 

i = (3* 2 +4 +5 ) ;

 

j = (3 * ((2+4) + 5));

 

System.out.println(“i:”+ i + “nj”:+j);

 

What is the result?

 

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 …

 

A.

Option A

B.

Option B

C.

Option C

D.

Option D

 

Correct Answer: B

 

 

QUESTION 96

Given:

 

public class Marklist {

 

int num;

 

public static void graceMarks(Marklist obj4) {

 

obj4.num += 10;

 

}

 

public static void main(String[] args){

 

MarkList obj1 = new MarkList();

 

MarkList obj2 = obj1;

 

MarkList obj1 = null;

 

obj2.num = 60;

 

graceMarks(obj2);

 

}

 

}

 

How many objects are created in the memory runtime?

 

A.

1

B.

2

C.

3

D.

4

 

Correct Answer: B

Explanation:

obj1 and obj3.

When you do e2 = e1you’re copying object references – you’re not making a copy of the object – and so the variables e1 and e2 will both point to the same object.

 

 

QUESTION 97

Given the code fragment:

 

public class ForTest {

 

public static void main(String[] args) {

 

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

 

for ( foo ) {

 

}

 

}

 

Which three code fragments,when replaced individually forfoo, enables the program to compile?

 

A.

int i : array

B.

int i = 0; i < 1;

C.

; ;

D.

; i < 1; i++

E.

i = 0; i<1;

 

Correct Answer: ABC

 

 

QUESTION 98

Which statement is true about the default constructor of a top-level class?

 

A.

It can take arguments.

B.

It has private access modifier in its declaration.

C.

It can be overloaded.

D.

The default constructor of a subclass always invokes the no-argument constructor of its superclass.

 

Correct Answer: D

Explanation:

In both Java and C#, a “default constructor” refers to a nullary constructor that is automatically generated by the compiler if no constructors have been defined for the class. The default constructor is also empty, meaning that it does nothing. A programmer- defined constructor that takes no parameters is also called a default constructor.

 

QUESTION 99

Given:

 

Class A { }

 

Class B { }

 

Interface X { }

 

Interface Y { }

 

Which two definitions of class C are valid?

 

A.

Class C extends A implements X { }

B.

Class C implements Y extends B { }

C.

Class C extends A, B { }

D.

Class C implements X, Y extends B { }

E.

Class C extends B implements X, Y { }

 

Correct Answer: AE

Explanation:

Extends is for extending a class.

Implements is for implementing an interface.

Java allows for a class to implement many interfaces.

 

 

QUESTION 100

Given:

 

public class TestOperator {

 

public static voidmain(String[] args) {

 

int result = 30 -12 / (2*5)+1;

 

System.out.print(“Result = ” + result);

 

}

 

}

 

What is the result?

 

A.

Result = 2

B.

Result = 3

C.

Result = 28

D.

Result = 29

E.

Result = 30

 

Correct Answer: E

 

Comments are closed.