0% found this document useful (0 votes)
578 views140 pages

Oracle Test-Inside 1z0-808 v2020-05-13 by James 121q PDF

This document contains a practice exam with 22 multiple choice questions about Java programming concepts like classes, objects, inheritance, encapsulation, and more. Each question includes possible answer options and an explanation of the correct answer. The questions cover topics like switch statements, exceptions, inheritance, method overloading, arrays, dates, and more.

Uploaded by

abnaod5363
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
578 views140 pages

Oracle Test-Inside 1z0-808 v2020-05-13 by James 121q PDF

This document contains a practice exam with 22 multiple choice questions about Java programming concepts like classes, objects, inheritance, encapsulation, and more. Each question includes possible answer options and an explanation of the correct answer. The questions cover topics like switch statements, exceptions, inheritance, method overloading, arrays, dates, and more.

Uploaded by

abnaod5363
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 140

1z0-808

Number: 1z0-808
Passing Score: 800
Time Limit: 120 min
File Version: 1

1z0-808

https://www.gratisexam.com/

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Exam A

QUESTION 1
Which statement is true about the switch statement?

https://www.gratisexam.com/

A. It must contain the default section.


B. The break statement, at the end of each case block, is optional.
C. Its case label literals can be changed at runtime.
D. Its expression must evaluate to a collection of values.

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 2
Given the code fragment:

What is the result?

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
A. Sum is 600
B. Compilation fails at line n1.
C. Compilation fails at line n2.
D. A ClassCastException is thrown at line n1.
E. A ClassCastException is thrown at line n2.

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 3
What is the name of the Java concept that uses access modifiers to protect variables and hide them within a class?

A. Encapsulation
B. Inheritance
C. Abstraction
D. Instantiation
E. Polymorphism

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:
Explanation:
Using the private modifier is the main way that an object encapsulates itself and hide data from the outside world.
Reference: http://www.tutorialspoint.com/java/java_access_modifiers.htm

QUESTION 4
Given:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A. Compilation fails at line n1.


B. Initialized
Started
Initialized
C. Initialized
Started
D. Compilation fails at line n2.

Correct Answer: A
Section: (none)
Explanation

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Explanation/Reference:

QUESTION 5
Given these two classes:

Any amount of electricity used by a customer (represented by an instance of the Customer class) must contribute to the customer's bill (represented by the member
variable bill) through the useElectricity method.

An instance of the Customer class should never be able to tamper with or decrease the value of the member variable bill.

How should you write methods in the ElectricAccount class at line n1 so that the member variable bill is always equal to the value of the member variable
kwh multiplied by the member variable rate?

A.

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
B.

C.

D.

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 6
Given the code fragment:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A. Match 1
B. Match 2
C. No Match
D. A NullPointerException is thrown at runtime.

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 7
Given:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
And given the code fragment:

Book book1 = new EBook();


book1.readBook();

Which option enables the code to compile?

A. Option A

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
B. Option B
C. Option C
D. Option D

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:

QUESTION 8
Given the code fragment:

Which option can replace xxx to enable the code to print 135?

A.
B.
C.

D.

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 9
Which statement best describes encapsulation?

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
A. Encapsulation ensures that classes can be designed so that only certain fields and methods of an object are accessible from other objects.
B. Encapsulation ensures that classes can be designed so that their methods are inheritable.
C. Encapsulation ensures that classes can be designed with some fields and methods declared as abstract.
D. Encapsulation ensures that classes can be designed so that if a method has an argument MyType x, any subclass of MyType can be passed to that method.

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 10
Given this class:

And given this main method, located in another class:

Which three lines, when inserted independently at line n1, cause the program to print a 0 balance? (Choose three.)

A. acct.setAmount(-acct.getAmount());

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
B. acct.amount = 0; <option D earlier>
C. acct.setAmount(0);
D. acct.getAmount() = 0; <option E earlier>
E. this.amount = 0; <option A earlier>
F. acct.changeAmount(0); <option F earlier>
G. acct.changeAmount(-acct.amount); <option G earlier>

Correct Answer: BDF


Section: (none)
Explanation

Explanation/Reference:

QUESTION 11
Given the code fragment:

Which code fragment prints red:blue:small:medium?

A.

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
B.

C.

D.

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:

QUESTION 12
Given the code fragment:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A.

B. Compilation fails only at line n1.


C. Compilation fails only at line n2.
D. Compilation fails only at line n3.
E. Compilation fails at both line n2 and line n3.

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:

QUESTION 13
Given the code fragment:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A. Sum is 600
B. Compilation fails at line n1.
C. Compilation fails at line n2.
D. A ClassCastException is thrown at line n1.
E. A ClassCastException is thrown at line n2.

Correct Answer: E
Section: (none)
Explanation

Explanation/Reference:

QUESTION 14
Given the code fragment:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A. [Robb, Rick, Bran]


B. [Robb, Rick]
C. [Robb, Bran, Rick, Bran]
D. An exception is thrown at runtime.

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 15
Given:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A. CBA
B. C
C. ABC
D. Compilation fails at line n1 and line n2

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
QUESTION 16
Given the code fragment:

Which code fragment, when inserted at line 3, enables the code to print 10:20?

A.

B.

C.

D.

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:
Explanation:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
QUESTION 17
Given the code from the Greeting.Java file:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Which set of commands prints Hello Duke in the console?

https://www.gratisexam.com/

A. Option A
B. Option B
C. Option C
D. Option D

Correct Answer: C
Section: (none)

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Explanation

Explanation/Reference:

QUESTION 18
Given the code fragment:

What is the result?

A. 24
B. 0246
C. 024
D. Compilation fails

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 19
Given the code fragment:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Assume that the system date is June 20, 2014. What is the result?

A.

B.

C. Compilation fails.
D. An exception is thrown at runtime.

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 20
Given:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A. Compilation fails.
B. false true
C. true false
D. true true
E. false false

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 21
Given the code fragment:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
And given the requirements:
If the value of the qty variable is greater than or equal to 90, discount = 0.5
If the value of the qty variable is between 80 and 90, discount = 0.2

Which two code fragments can be independently placed at line n1 to meet the requirements? (Choose two.)

A. Option A
B. Option B

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
C. Option C
D. Option D
E. Option E

Correct Answer: AC
Section: (none)
Explanation

Explanation/Reference:

QUESTION 22
Given:

And given the commands:

What is the result?

A. Success
B. Failure
C. Compilation fails.

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
D. An exception is thrown at runtime

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 23
Given:

Acc.java:

Which statement is true?

A. Both p and s are accessible via obj.


B. Only s is accessible via obj.
C. Both r and s are accessible via obj.

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
D. p, r, and s are accessible via obj.

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 24
Given:

What is the result?

A. Option A
B. Option B
C. Option C
D. Option D

Correct Answer: D
Section: (none)
Explanation

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Explanation/Reference:

QUESTION 25
Given the code fragment:

What is the result?

A. ABC
B. ABCDE
C. ABDE
D. Compilation fails.

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 26
Given the code fragment:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A. true true
B. true false
C. false false
D. false true

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 27
Given the code fragment:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Which code fragment, when inserted at line n1, enables the App class to print Equal?

A. Option A
B. Option B
C. Option C
D. Option D

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 28
Given the code fragment:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A. 1 2 3 4
followed by an ArrayIndexOutOfBoundsException
B. 1 2 3
C. 1 2 3 4
D. Compilation fails.

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:
Explanation:

QUESTION 29
Given the definitions of the MyString class and the Test class:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A.

B.

C.

D. Compilation fails at the Test class

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
QUESTION 30
Given this code for a Planet object:

What is the output?

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
A.

B.

C.

D.

E.

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 31
Given this array:

Which two code fragments, independently, print each element in this array? (Choose two.)

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
A.

B.

C.

D.

E.

F.

Correct Answer: BE
Section: (none)
Explanation

Explanation/Reference:

QUESTION 32
Given:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
How many MarkList instances are created in memory at runtime?

A. 1
B. 2
C. 3
D. 4

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 33
Given:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A. Area is 6.0
B. Area is 3.0
C. Compilation fails at line n1
D. Compilation fails at line n2.

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 34
Given:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A. True false
B. True null
C. Compilation fails
D. A NullPointerException is thrown at runtime

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 35
Given:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A. myStr: 9009, myNum: 9009


B. myStr: 7007, myNum: 7007
C. myStr: 7007, myNum: 9009
D. Compilation fails

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
QUESTION 36
Given the code fragment:

What is the result?

A. 1:2:3:4:5:
B. 1:2:3:
C. Compilation fails.
D. An ArrayOutOfBoundsException is thrown at runtime.

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 37
Given:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A. true:true
B. true:false
C. false:true
D. false:false

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 38
Given the code fragment:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A. 1324
B. 2313
C. 3142
D. 4231

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:

QUESTION 39
Given:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A. An exception is thrown at runtime.


B. Initialized
Started
Initialized
C. Initialized
Started
D. Compilation fails.

Correct Answer: D
Section: (none)
Explanation

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Explanation/Reference:

QUESTION 40
Given the code fragment:

What is the result?

A. Answer = 0
B. Invalid calculation
C. Compilation fails only at line n1.
D. Compilation fails only at line n2.
E. Compilation fails at line n1 and line2.

Correct Answer: E
Section: (none)
Explanation

Explanation/Reference:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
QUESTION 41
Given:

What is the result?

A. 100 200 : 0 0 :
B. 100 200 : 100 0 :
C. 100 200 : 100 200 :
D. 0 0 : 100 0 :

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 42
Given:

What is the result?

A. a, e
i, i
B. a, e
o, o

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
C. e, e
i, i
D. a, a
o, o

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 43
Given the code fragment:

What is the result if the integer aVar is 9?

A. Compilation fails.
B. 10 Hello Universe!
C. 10 Hello World!
D. 9 Hello World!

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 44
Which statement will empty the contents of a StringBuilder variable named sb?

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
A. sb. deleteAll ();
B. sb. delete (0, sb. size () );
C. sb. delete (0, sb. length () );
D. sb. removeAll ();

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 45
Which statement is true about the switch statement?

A. It must contain the default section.


B. The break statement, at the end of each case block, is mandatory.
C. Its case label literals can be changed at runtime.
D. Its expression must evaluate to a single value.

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:
Reference: http://www.dummies.com/programming/java/switch-statements-in-java/

QUESTION 46
Given the code fragment:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Test.java

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Which is the result?

A. Compilation fails in the Employee class.


B.

C.

D. Compilation fails in the Test class.


E. Both the Employee class and the Test class fail to compile.

Correct Answer: E
Section: (none)
Explanation

Explanation/Reference:

QUESTION 47
Given the code fragments:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Which modification enables the code to compile?

A.

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
B.

C.

D.

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 48
Which three statements are true about the structure of a Java class? (Choose three.)

A. A public class must have a main method.


B. A class can have only one private constructor.
C. A method can have the same name as a field.
D. A class can have overloaded static methods.
E. The methods are mandatory components of a class.
F. The fields need not be initialized before use.

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Correct Answer: ACE
Section: (none)
Explanation

Explanation/Reference:

QUESTION 49
Given:

What is the result?

A. Compilation fails at line n3 and line n4.


B. Compilation fails at line n1 and line n2.
C. Welcome Visit Count:1
Welcome Visit Count: 1
D. Welcome Visit Count:1
Welcome Visit Count: 2

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
QUESTION 50
Given the code fragment:

What is the result?

A. Compilation fails at both line n1 and line n2.

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
B. Compilation fails only at line n2.
C. Compilation fails only at line n1.
D. Jesse 25
Walter 52

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 51
Given the code fragment:

What is the result?

A. A NullPointerException is thrown at runtime.


B. [1, 2, 4]
C. [1, 2, 4, null]

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
D. [1, 3, 4, null]
E. [1, 3, 4]
F. Compilation fails.

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:
Explanation:

QUESTION 52
Which two code fragments cause a compilation error? (Choose two.)

A. float flt = 100.00F;


B. float flt = (float) 1_11.00;
C. Float flt = 100.00;
D. double y1 = 203.22;
float flt = y1;
E. int y2 = 100;
float flt = (float) y2 ;

Correct Answer: AD
Section: (none)
Explanation

Explanation/Reference:

QUESTION 53
Given:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A.

B.

C.

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
D.

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 54
Which three statements are true about exception handling? (Choose three.)

A. Only unchecked exceptions can be rethrown.


B. All subclasses of the RuntimeException class are not recoverable.
C. The parameter in a catch block is of Throwable type.
D. All subclasses of the RuntimeException class must be caught or declared to be thrown.
E. All subclasses of the RuntimeException class are unchecked exceptions.
F. All subclasses of the Error class are not recoverable.

Correct Answer: BCD


Section: (none)
Explanation

Explanation/Reference:

QUESTION 55
Given the code fragment:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A. An exception is thrown at runtime.


B. -1
C. 5
D. 10

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 56
Which two statements are true? (Choose two.)

A. Error class is unextendable.


B. Error class is extendable.
C. Error is a RuntimeException.
D. Error is an Exception.
E. Error is a Throwable.

Correct Answer: BE
Section: (none)
Explanation

Explanation/Reference:

QUESTION 57

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Given the code fragment:

https://www.gratisexam.com/

What is the result?

A. Compilation fails.
B. 0 Found
C. 1 Found
D. 3 Found

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
QUESTION 58
Given:

And given the commands:

What is the result?

A. Java SE
B. Java EE
C. Compilation fails at line n1.
D. A NullPointerException is thrown at runtime.

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
QUESTION 59
Given the code fragment:

What is the result?

A. An exception is thrown at runtime.


B. Compilation fails.
C. 13480.0
D. 13480.02

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:

QUESTION 60
Given:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
And given the code fragment:

What is the result?

A. C2C2

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
B. C1C2
C. C1C1
D. Compilation fails

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 61
Given:

Given the code fragment:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Which two sets of actions, independently, enable the code fragment to print Fit?

A. At line n1 insert: import clothing.Shirt;


At line n2 insert: String color = Shirt.getColor();
B. At line n1 insert: import clothing;
At line n2 insert: String color = Shirt.getColor();
C. At line n1 insert: import static clothing.Shirt.getColor;
At line n2 insert: String color = getColor();
D. At line n1 no changes required.
At line n2 insert: String color = Shirt.getColor();
E. At line n1 insert: import Shirt;
At line n2 insert: String color = Shirt.getColor();

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:

QUESTION 62
Given the code fragments:

And:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Which statement is true?

A. After line 11, three objects are eligible for garbage collection.
B. After line 11, two objects are eligible for garbage collection.
C. After line 11, one object is eligible for garbage collection.
D. After line 11, none of the objects are eligible for garbage collection.

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 63
Given the code fragment:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A. 3
B. 4
C. -1
D. Compilation fails.

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
QUESTION 64
Given the code fragment:

What is the result?

A. 2012-02-10
B. 2012-02-11
C. Compilation fails
D. A DateTimeException is thrown at runtime.

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:

QUESTION 65
Given:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
And given the code fragment:

What is the result?

A. Compilation fails at line n2.


B. Read Book
C. Read E-Book
D. Compilation fails at line n1.
E. Compilation fails at line n3.

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Correct Answer: E
Section: (none)
Explanation

Explanation/Reference:

QUESTION 66
Given this class:

Which two changes would encapsulate this class and ensure that the area field is always equal to length * height whenever the Rectangle class is used?

A. Call the setArea method at the end of the setHeight method.


B. Call the setArea method at the beginning of the setHeight method.
C. Call the setArea method at the end of the setLength method.
D. Call the setArea method at the beginning of the setLength method.
E. Change the setArea method to private.
F. Change the area field to public.

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Correct Answer: AC
Section: (none)
Explanation

Explanation/Reference:

QUESTION 67
Given the code fragment:

What is the result?

A. Compilation fails.
B. Hi removed
C. An UnsupportedOperationException is thrown at runtime.
D. The program compiles, but it prints nothing.

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 68
Which two class definitions fail to compile? (Choose two.)

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
A.

B.

C.

D.

E.

Correct Answer: CD
Section: (none)
Explanation

Explanation/Reference:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
QUESTION 69
Given:

What is the result?

A. null
Richard
Donald
B. Richard
Donald
C. Compilation fails.
D. An ArrayIndexOutOfBoundsException is thrown at runtime.
E. A NullPointerException is thrown at runtime.

Correct Answer: E

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Section: (none)
Explanation

Explanation/Reference:

QUESTION 70
This grid shows the state of a 2D array:

The grid is created with this code:

Which line of code, when inserted in place of //line n1, adds an X into the grid so that the grid contains three consecutive XS?

A. grid[2][1] = ‘X’;
B. grid[3][2] = ‘X’;
C. grid[3][1] = ‘X’;
D. grid[2][3] = ‘X’;

Correct Answer: D
Section: (none)
Explanation

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Explanation/Reference:

QUESTION 71
Given the code fragment:

Which two modifications should you make so that the code compiles successfully? (Choose two.)

A. Replace line 13 with:

B. Replace line 7 with throw IOException (“Exception raised”);


C. Replace line 11 with public static void main(String[]) args) throws Exception {
D. At line 14, insert throw new IOException();
E. Replace line 5 with public void printFileContent() throws IOException {

Correct Answer: CE
Section: (none)
Explanation

Explanation/Reference:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
QUESTION 72
Given the code fragment:

What is the result?

A. 1 3 5 7
13
B. 1 3
13
C. 1 3
1300
D. 1 3
followed by an ArrayIndexOutOfBoundsException
E. Compilation fails.

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:
Explanation:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
QUESTION 73
Which is true about the switch statement?

A. Its expression can evaluate to a collection of values.


B. The break statement, at the end of each case block, is optional.
C. Its case label literals can be changed at runtime.
D. It must contain the default section.

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:
Reference: https://www.geeksforgeeks.org/switch-statement-in-java/

QUESTION 74
Given the code fragment:

What is the result?

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
A. 3142
B. 2413
C. 1324
D. 4231

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:
Explanation:

QUESTION 75
Given:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A. 95
B. 81 25
C. Compilation fails.
D. 00

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:
Explanation:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
QUESTION 76
Given the code fragments:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A. Compilation fails only at line n1.


B. Compilation fails only at line n2.
C. Tool::export
Tool::export
D. Compilation fails at both line n1 and line2.
E. RTool::export

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Tool::export

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:

QUESTION 77
Given the code snippet from a compiled Java source file:

and this output:

Which command should you run to obtain this output?

A. java MyFile 2
B. java MyFile 1 2 3 4
C. java MyFile 1 2 2
D. java MyFile 2 2

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
QUESTION 78
Given the code fragment:

What is the result?

A. 3
B. 0
C. Compilation fails.
D. -1

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:

QUESTION 79
Given the code fragment:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A. Compilation fails.
B. The program compiles, but it prints nothing.
C. HiHowAreYou removed
D. An UnsupportedOperationException is thrown at runtime.

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 80
Given the code fragment:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A.

B.

C. Invalid Name
D.

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:
Explanation:

QUESTION 81
Given:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
And the code fragment:

What is the result?

A. C1C2
B. C1C1
C. Compilation fails.
D. C2C2

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:
Explanation:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
QUESTION 82
https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Given the code fragment:

What is the result?

A. 24
B. 0246
C. 024
D. Compilation fails.

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:
Explanation:

QUESTION 83
Given the code fragment:

And given the requirements:


1. Process all the elements of the array in the reverse order of entry.
https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
2. Process all the elements of the array in the order of entry.
3. Process alternating elements of the array in the order of entry.

Which two statements are true? (Choose two.)

A. Requirements 1, 2, and 3 can be implemented by using the enhanced for loop.


B. Requirements 1, 2, and 3 can be implemented by using the standard for loop.
C. Requirements 2 and 3 CANNOT be implemented by using the standard for loop.
D. Requirement 2 can be implemented by using the enhanced for loop.
E. Requirement 3 CANNOT be implemented by using either the enhanced for loop or the standard for loop.

Correct Answer: BC
Section: (none)
Explanation

Explanation/Reference:

QUESTION 84
Given:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A. 97 98
99 100 null null null
B. 97 98

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
99 100 101 102 103
C. Compilation fails.
D. A NullPointerException is thrown at runtime.
E. An ArraylndexOutOfBoundsException is thrown at runtime.

Correct Answer: E
Section: (none)
Explanation

Explanation/Reference:
Explanation:

QUESTION 85
Given the code fragment:

Which code fragment, when inserted at line n1, enables the App class to print Equal?

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
A. Option A
B. Option B
C. Option C
D. Option D

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 86
Given the code fragment:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A. ABC
B. ABCDE
C. ABDE
D. Compilation fails.

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:

QUESTION 87
Given the code fragment:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Test.java:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Which is the result?

A. Compilation fails in the Employee class.


B.

C.

D. Compilation fails in the Test class.


E. Both the Employee class and the Test class fail to compile.

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:

QUESTION 88
Given:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A.

B.

C.

D.

Correct Answer: A
Section: (none)
https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Explanation

Explanation/Reference:

QUESTION 89
Given the code fragment:

Which modification enables the code to print 54321?

A. Replace line 6 with System.out.print (--x);


B. At line 7, insert x --;
C. Replace line 5 with while (is Available(--x)) {
D. Replace line 12 with return (x > 0) ? false : true;

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 90
Given:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A. A
B
B. A
C
C. C

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
C
D. A ClassCastException is thrown only at line n1.
E. A ClassCastException is thrown only at line n2.

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:

QUESTION 91
Given:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
A. Base
DerivedA
B. Base
DerivedB
C. DerivedB
DerivedB
D. DerivedB
DerivedA
E. A ClassCastException is thrown at runtime.

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:

QUESTION 92
Given the definitions of the MyString class and the Test class:

What is the result?

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
A.

B.

C.

D. Compilation fails at the Test class

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:

QUESTION 93
Given:

What is the result?

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
A. Compilation fails.
B. false true
C. true false
D. true true
E. false false

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:
Explanation:

QUESTION 94
Given:

What is the result?

A. A B C D
B. A C D

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
C. A C D D
D. A B C C
E. A B D C

Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:
Explanation:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
QUESTION 95
https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Given the definitions of the Bird class and the Peacock class:

and the code fragment:

Which code snippet can be inserted to print Fly.Dance. ?

A. Bird p = new Peacock();


B. Bird b = new Bird();
Peacock p = (Peacock) b;
C. Peacock b = new Peacock ();
Bird p = (Bird) b;
D. Bird b = new Peacock ();
Peacock p = (Peacock) b;

Correct Answer: B
Section: (none)
Explanation

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Explanation/Reference:

QUESTION 96
Given the code fragment:

What is the result?

A. 11
B. 10
C. 12
D. A compile time error occurs.

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:
Explanation:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
QUESTION 97
Given the code fragment:

What is the result?

A. 2 : 7 : 3
B. 7 : 7 : 9
C. 2 : 7 : 0
D. 7 : 2 : 3

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:
Explanation:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
QUESTION 98
Given:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Which action fixes the compiler error?

A. At line 17, add throws AccessViolationException


B. At line 13, add throws LogFileException
C. At line 2, replace throws LogFileException with throws AccessViolationException
D. At line 7, insert throw new LogFileException ();

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
QUESTION 99
Given the code fragment:

What is the result?

A. 1 2 3 0 0
1 2 3 0 0
B. An Exception is thrown at run time.
C. 1 2 3 0 0
1 2 3
D. 1 2 3
1 2 3

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:
Explanation:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
QUESTION 100
Given the code fragment:

What is the result?

A. It results in a compile time error at line 18.


B. It results in a compile time error at line 9.
C. It prints : 1
D. It results in a compile time error at lines at lines 12 and 15.

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Correct Answer: A
Section: (none)
Explanation

Explanation/Reference:
Explanation:

QUESTION 101
Given:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
And:

What is the result?

A. ns = 100 s =125
ns = 0 s = 125
ns = 125 s = 125

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
B. ns = 50 s = 50
ns = 125 s = 125
ns = 0 s = 125
C. ns = 50 s = 125
ns = 125 s = 125
ns = 0 s = 125
D. ns = 50 s = 50
ns = 125 s =125
ns = 100 s =100

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 102
Which two array initialization statements are valid? (Choose two.)

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


B. int array[] = new int[3];
array[0] = 1;
array[1] = 2;
array[2] = 3;
C. int array[3] = new int[] {1, 2, 3};
D. int array[] = new int[3];
array = {1, 2, 3};
E. int array[] = new int[] {1,2,3};

Correct Answer: BE
Section: (none)
Explanation

Explanation/Reference:
Reference: https://stackoverflow.com/questions/1200621/how-do-i-declare-and-initialize-an-array-in-java

QUESTION 103
Given the class definitions:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
class C1 {}
class C2 extends C1 {}
class C3 extends C2 {}

and the code fragment:

16. C1 obj1 = (C1) new C2();


17. C2 obj2 = (C2) new C3();
18. C2 obj3 = (C2) new C1();
19. C3 obj4 = (C3) obj2;

Which line throws ClassCastException?

A. line 18
B. line 17
C. line 19
D. line 16

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:
Explanation:

QUESTION 104
Which two features can be implemented in a Java application by encapsulating the entity classes used? (Choose two.)

A. data validation
B. compile time polymorphism
C. data hiding
D. data abstraction
E. data memory optimization

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Correct Answer: CD
Section: (none)
Explanation

Explanation/Reference:
Reference: https://www.geeksforgeeks.org/encapsulation-in-java/

QUESTION 105
Given the code fragment:

What is the result?

A. The sum of 4 numbers is: 10


B. A compile time error occurs.
C. The sum of 5 numbers is: 10
D. The sum of 5 numbers is: 15

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:
Explanation:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
QUESTION 106
Given the code fragment:

What is the result?

A. [JavaForum, ExpertForum]
B. [JavaGroup, ExpertGroup]
C. [JavaForumGroup, ExpertForumGroup]
D. [JavaGroup, TechGroup ExpertGroup]

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:
Explanation:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
QUESTION 107
Examine the given definitions:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
and the code fragment:

Which statement is true about the implementation of Object-Oriented Programming concepts in the given code?

A. Polymorphism, abstraction, and encapsulation are implemented.


B. Only polymorphism and inheritance are implemented.
C. Polymorphism, inheritance, and abstraction are implemented.
D. Only inheritance and encapsulation are implemented.

Correct Answer: C
Section: (none)
Explanation

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Explanation/Reference:

QUESTION 108
Given:

What is the result?

A. true
B. false
C. -1
D. 0

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:
Explanation:

QUESTION 109
Given:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
and the code fragment:

S2 sobj = new S2();


sobj.display(10, 100);

What is the result?

A. Child 10
Child 100
Parent 100
B. Parent 10
Child 10
Parent 1000
C. Child 10
Parent 100
Parent 100

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
D. A compile time error occurs.

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:
Explanation:

QUESTION 110
Given the code fragment:

https://www.gratisexam.com/
What is the result?

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
A. EN FR JP
B. EN FR
C. CH
D. EN FR CH

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:
Explanation:

QUESTION 111
Given:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
and the code fragment:

What is the result?

A. true:false:true
B. false:true:true
C. false:true:false
D. true:true:false

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:
Explanation:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
QUESTION 112
Given:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A. Good Luck!
B. Good Day!
C. Welcome!
D. Hello!

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:
Explanation:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
QUESTION 113
Given:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A. 10
20
B. A compile time error occurs
C. 20
20
D. 10
10

Correct Answer: B
Section: (none)
https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Explanation

Explanation/Reference:
Explanation:

QUESTION 114
Given these requirements:
Bus and Boat are Vehicle type classes.
The start() and stop() methods perform common operations across the Vehicle class type.
The ride() method performs a unique operations for each type of Vehicle.

Which set of actions meets the requirements with optimized code?

A. 1. Create an abstract class Vehicle by defining start() and stop() methods, and declaring the ride() abstract method.
2. Create Bus and Boat classes by inheriting the Vehicle class and overriding the ride() method.
B. 1. Create an interface Vehicle by defining start() and stop() methods, and declaring the ride() abstract method.
2. Create Bus and Boat classes by implementing the Vehicle class.
C. 1. Create an abstract class Vehicle by declaring stop(), start(), and ride() abstract methods.
2. Create Bus and Boat classes by inheriting the Vehicle class and overriding all the methods.
D. 1. Create an interface Vehicle by defining default stop(), start(), and ride() methods.
2. Create Bus and Boat classes by implementing the Vehicle interface and overriding the ride() method.

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:

QUESTION 115
Given:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A. null:null:0.0
B. null:null
C. <<HashCode>>:0.0
D. null:0.0

Correct Answer: D
Section: (none)
Explanation

Explanation/Reference:
Explanation:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
QUESTION 116
Examine the content of App.java:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Which is true?

A. The App.class file is stored within the p1 folder. The Test.class file is stored within the p2 sub-folder of p1.
B. The App class is accessible within the Test class without an import statement.
C. import p1.App; is used to access the App class within the Test class.
D. It is optional to have the package statement as the first line of class definitions.

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:

QUESTION 117
Given the code fragment:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
Which code snippet at line 9 prints true?

A. Boolean s = p.apply(101);
System.out.println(s);
B. Boolean s = p.test(100);
System.out.println(s);
C.

D. System.out.println(p.apply(100));

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:
Explanation:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
QUESTION 118
Given:

What is the result?

A. double sum is 30.0

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
float sum is 30.0
B. float sum is 30.0
double sum is 30.0
C. Integer sum is 30
double sum is 30.0
D. Integer sum is 30
float sum is 30.0

Correct Answer: B
Section: (none)
Explanation

Explanation/Reference:
Explanation:

QUESTION 119
Given:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A. c=null
b=true
f=0.0
B. c=
b=false
f=0.0
C. c=null
b=false
f=0.0
D. c=0
b=false
f=0.0F

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:
Explanation:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
QUESTION 120
Which two code fragments cause compilation errors? (Choose two.)

A. double y1 = 203.22;
float fit = y1;
B. float fit = (float) 1_11.00;
C. Float fit = 100.00;
D. int y2 = 100;
float fit = (float) y2;
E. float fit = 100.00F;

Correct Answer: BD
Section: (none)
Explanation

Explanation/Reference:

QUESTION 121
Given:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
What is the result?

A. myStr: 7007, myNum: 7007


B. Error
C. myStr: 9009, myNum: 7007

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2
https://www.gratisexam.com/

D. myStr: 7007, myNum: 9009

Correct Answer: C
Section: (none)
Explanation

Explanation/Reference:
Explanation:

https://www.gratisexam.com/
885CB989129A5F974833949052CFB2F2

You might also like