100% de satisfacción garantizada Inmediatamente disponible después del pago Tanto en línea como en PDF No estas atado a nada 4,6 TrustPilot
logo-home
Examen

OCP 17 Java Final Exam Questions With Guaranteed Pass Solutions.

Puntuación
-
Vendido
-
Páginas
242
Grado
A+
Subido en
18-05-2025
Escrito en
2024/2025

What is the result of the following program? 1: public class Squares { 2: ....public static long square(int x) { 3: ....var y = x * (long) x; 4: ....x = -1; 5: ....return y; 6: } 7: public static void main(String[] args) { 8: ...var value = 9; 9: ...var result = square(value); 10: ..Sln(value); 11: } } A. -1 B. 9 C. 81 D. Compiler error on line 9 E. Compiler error on a different line - Answer B. Since Java is pass-by-value and the variable on line 8 never gets reassigned, it stays as 9. In the method square, x starts as 9. The y value becomes 81, and then x gets set to -1. Line 9 does set result to 81. However, we are printing out value, and that is still 9, making option B correct. Which of the following are legal entry point methods that can be run from the command line? (Choose all that apply.) A. private static void main(String[] args) B. public static final main(String[] args) C. public void main(String[] args) D. public static final void main(String[] args) E. public static void main(String[] args) F. public static main(String[] args) - Answer D, E. Option E is the canonical main() method signature. You need to memorize it. Option D is an alternate form with the redundant final. Option A is incorrect because the main() method must be public. Options B and F are incorrect

Mostrar más Leer menos
Institución
OCP Oracle Certified Professional Java SE 21
Grado
OCP Oracle Certified Professional Java SE 21











Ups! No podemos cargar tu documento ahora. Inténtalo de nuevo o contacta con soporte.

Escuela, estudio y materia

Institución
OCP Oracle Certified Professional Java SE 21
Grado
OCP Oracle Certified Professional Java SE 21

Información del documento

Subido en
18 de mayo de 2025
Número de páginas
242
Escrito en
2024/2025
Tipo
Examen
Contiene
Preguntas y respuestas

Temas

Vista previa del contenido

OCP 17 Java Final Exam Questions With
Guaranteed Pass Solutions.
What is the result of the following program?

1: public class Squares {

2: ....public static long square(int x) {

3: ....var y = x * (long) x;

4: ....x = -1;

5: ....return y;

6: }

7: public static void main(String[] args) {

8: ...var value = 9;

9: ...var result = square(value);

10: ..System.out.println(value);

11: } }



A. -1

B. 9

C. 81

D. Compiler error on line 9

E. Compiler error on a different line - Answer B. Since Java is pass-by-value and the variable on
line 8 never gets reassigned, it stays as 9. In the method square, x starts as 9. The y value
becomes 81, and then x gets set to -1. Line 9 does set result to 81. However, we are printing out
value, and that is still 9, making option B correct.



Which of the following are legal entry point methods that can be run from the command line?
(Choose all that apply.)



A. private static void main(String[] args)

B. public static final main(String[] args)

C. public void main(String[] args)

D. public static final void main(String[] args)

,because the main() method must have a void return type. Option C is incorrect because the
main() method must be static.



Which answer options represent the order in which the following statements can be assembled
into a program that will compile successfully? (Choose all that apply.)



X: class Rabbit {}

Y: import java.util.*;

Z: package animals;



A. X, Y, Z

B. Y, Z, X

C. Z, Y, X

D. Y, X

E. Z, X

F. X, Z

G. None of the above - Answer C, D, E. The package and import statements are both optional.
If both are present, the order must be package, then import, and then class. Option A is
incorrect because class is before package and import. Option B is incorrect because import is
before package. Option F is incorrect because class is before package.



Which of the following are true? (Choose all that apply.)

public class Bunny {

public static void main(String[] x) {

Bunny bun = new Bunny();

}}



A. Bunny is a class.

B. bun is a class.

C. main is a class.

D. Bunny is a reference to an object.

E. bun is a reference to an object.

F. main is a reference to an object.

,Which of the following are valid Java identifiers? (Choose all that apply.)



A. _

B. _helloWorld$

C. true

D. java.lang

E. Public

F. 1980_s

G. _Q2_ - Answer B, E, G.

Option A is invalid because a single underscore is not allowed. Option C is not a valid identifier
because true is a Java reserved word. Option D is not valid because a period (.) is not allowed in
identifiers. Option F is not valid because the first character is not a letter, dollar sign ($), or
underscore (_). Options B, E, and G are valid because they contain only valid characters.



Which statements about the following program are correct? (Choose all that apply.)



2: public class Bear {

3: ....private Bear pandaBear;

4:.... private void roar(Bear b) {

5: ..........System.out.println("Roar!");

6: ..........pandaBear = b;

7: }

8: public static void main(String[] args) {

9: ..Bear brownBear = new Bear();

10: ..Bear polarBear = new Bear();

11: ...brownBear.roar(polarBear);

12: ..polarBear = null;

13: ..brownBear = null;

14:... System.gc(); } }



A. The object created on line 9 is eligible for garbage collection after line 13.

, F. Garbage collection might or might not run.

G. The code does not compile. - Answer A, D, F. Garbage collection is never guaranteed to run,
making option F correct and option E incorrect. Next, the class compiles and runs without issue,
so option G is incorrect. The Bear object created on line 9 is accessible until line 13 via the
brownBear reference variable, which is option A. The Bear object created on line 10 is
accessible via both the polarBear reference and the brownBear.pandaBear reference. After line
12, the object is still accessible via brownBear.pandaBear. After line 13, though, it is no longer
accessible since brownBear is no longer accessible, which makes option D the final answer.



Assuming the following class compiles, how many variables defined in the class or method are
in scope on the line marked on line 14?



1: public class Camel {

2:..... { int hairs = 3_000_0; }

3: .....long water, air=2;

4: ......boolean twoHumps = true;

5:...... public void spit(float distance) {

6: ..........var path = "";

7: ..........{ double teeth = 32 + distance++; }

8: ..........while(water > 0) {

9: ..................int age = twoHumps ? 1 : 2;

10:................ short i=-1;

11: .......................for(i=0; i<10; i++) {

12: .....................................var Private = 2;

13: .......................}

14: ................// SCOPE

15:......... }

16: ......}

17: }



A. 2

B. 3

C. 4
$18.99
Accede al documento completo:

100% de satisfacción garantizada
Inmediatamente disponible después del pago
Tanto en línea como en PDF
No estas atado a nada


Documento también disponible en un lote

Conoce al vendedor

Seller avatar
Los indicadores de reputación están sujetos a la cantidad de artículos vendidos por una tarifa y las reseñas que ha recibido por esos documentos. Hay tres niveles: Bronce, Plata y Oro. Cuanto mayor reputación, más podrás confiar en la calidad del trabajo del vendedor.
TestSolver9 Webster University
Seguir Necesitas iniciar sesión para seguir a otros usuarios o asignaturas
Vendido
758
Miembro desde
2 año
Número de seguidores
126
Documentos
25136
Última venta
2 días hace
TESTSOLVER9 STORE

TOPNOTCH IN LEARNING MATERIALS,(EXAMS,STUDYGUIDES NOTES ,REVIEWS,FLASHCARDS ,ALL SOLVED AND PACKAGED.OUR STORE MAKE YOUR EDUCATION JOURNEY EFFICIENT AND EASY.WE ARE HERE FOR YOU FEEL FREE TO REACH US OUT .

3.6

133 reseñas

5
60
4
19
3
22
2
9
1
23

Recientemente visto por ti

Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes