Ensurepass

 

QUESTION 61

Which code fragment is illegal?

 

clip_image002

 

A.

Option A

B.

Option B

C.

Option C

D.

Option D

 

Correct Answer: D

Explanation:

The abstract keyword cannot be used to declare an int variable.

 

The abstract keyword is used to declare a class or method to beabstract[3]. An abstract method has no implementation; all classes containing abstract methods must themselves be abstract, although not all abstract classes have abstract methods.

 

 

QUESTION 62

The protected modifier on a Field declaration within a public class means that the field ______________.

 

 

Correct Answer: D

Explanation:

http://beginnersbook.com/2013/05/java-access-modifiers/

 

 

QUESTION 63

Given:

 

public class Natural {

 

private int i;

 

void disp() {

 

while (i <= 5) {

 

for (int i=1; i <=5;) {

 

System.out.print(i + ” “);

 

i++;

 

}

 

i++;

 

}

 

}

 

public static void main(String[] args) {

 

new Natural().disp();

 

}

 

}

 

What is the result?

 

A.

Cannot be modified

B.

Can be read but not written from outside the class

C.

Can be read and written from this class and its subclasses only within the same package

D.

Can be read and written from this class and its subclasses defined in any package

A.

Prints 1 2 3 4 5 once

B.

Prints 1 3 5 once

C.

Prints 1 2 3 4 5 five times

D.

Prints1 2 3 4 5 six times

E.

Compilation fails

 

Correct Answer: D

Explanation:

1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5 1 2 3 4 5

 

 

 

 

QUESTION 64

Given:

 

clip_image003

 

What is the result?

 

A.

Shining Sun

Shining Sun

Shining Sun

B.

Shining Sun

Twinkling Star

Shining Sun

C.

Compilation fails

D.

A ClassCastException is thrown at runtime

 

Correct Answer: D

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

QUESTION 65

Given:

 

clip_image005

 

What is the result?

 

A.

Good Day!

Good Luck!

B.

Good Day!

Good Day!

C.

Good Luck!

Good Day!

D.

Good Luck!

Good Luck!

E.

Compilation fails

 

Correct Answer: E

 

 

QUESTION 66

Given the code fragment:

 

String[] cartoons = {“tom”,”jerry”,”micky”,”tom”};

 

int counter =0;

 

if (“tom”.equals(cartoons[0])) {

 

counter++;

 

} else if (“tom”.equals(cartoons[1])) {

 

counter++;

 

} else if (“tom”.equals(cartoons[2])) {

 

counter++;

 

} else if (“tom”.equals(cartoons[3])) {

 

counter++;

 

}

 

System.out.print(counter);


 

What is the result?

 

A.

1

B.

2

C.

4

D.

0

 

Correct Answer: A

Explanation:

Counter++ will be executed only once because of the else if constructs.

 

 

QUESTION 67

Given:

 

clip_image007

 

What is the result?

 

A.

100

B.

Compilation fails due to an error in line n1

C.

Compilation fails due to an error at line n2

D.

Compilation fails due to an error at line n3

 

Correct Answer: C

 

 

 

QUESTION 68

Given:

 

clip_image009

 

Which code fragment, when inserted at line 9, enables the code to print true?

 

A.

String str2 =str1;

B.

String str2 = new string (str1);

C.

String str2 = sb1.toString();

D.

String str2 = “Duke”;

 

Correct Answer: B

 

 

QUESTION 69

Given:

 

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 …

 

What is the result?

 

A.

true true

B.

true false

C.

false true

D.

false false

E.

Compilation fails

 

Correct Answer: E

 

 

 

 

 

 

 

QUESTION 70

Given:

 

class Base {

 

// insert code here

 

}

 

public class Derived extends Base{

 

public static void main(String[] args) {

 

Derived obj = new Derived();

 

obj.setNum(3);

 

System.out.println(“Square = ” + obj.getNum() * obj.getNum());

 

}

 

}

 

Which two options, when inserted independently inside class Base, ensure that the class is being properly encapsulated and allow the program to execute and print the square of the number?

 

A.

private int num;public int getNum() {return num;}public void setNum(int num) {this.num = num;}

B.

public int num;protected public int getNum() {return num;}protected public void setNum(int num) {this.num = num;}

C.

private int num;public int getNum() {return num;}private void setNum(int num) {this.num = num;}

D.

protected int num;public int getNum() {return num;}public void setNum(int num) {this.num = num;}

E.

protected int num;private int getNum() {return num;}public void setNum(intnum) {this.num = num;}

 

Correct Answer: AD

Explanation:

Incorrect:

Not B: illegal combination of modifiers: protected and public

not C: setNum method cannot be private.

not E: getNum method cannot be private.

 

Comments are closed.