Escrito por estudiantes que aprobaron Inmediatamente disponible después del pago Leer en línea o como PDF ¿Documento equivocado? Cámbialo gratis 4,6 TrustPilot
logo-home
Document preview thumbnail
Vista previa 2 fuera de 6 páginas
Examen

Java OOP Advanced Exam Questions and Answers — Inheritance, Polymorphism, Exceptions

Document preview thumbnail
Vista previa 2 fuera de 6 páginas

Advanced Java OOP exam covering the most challenging topics tested in second-year Computer Science courses. 25 questions with detailed verified answers and explanations. Topics covered: - Constructor inheritance and polymorphism in superclass constructors - Abstract classes vs interfaces — when to use each - Method overriding with dynamic (runtime) binding - Static binding vs dynamic binding — which applies to static methods - ArrayList: removeAll(), equals(), remove(index) vs remove(value) - Exception handling: try/catch/finally, RuntimeException hierarchy - Short-circuit evaluation (&& and ||) - Immutable objects — requirements and implementation - Preventing instantiation with private constructors - instanceof across sibling classes - do-while loops, continue, and break behavior - Common Java pitfalls: = vs ==, post-increment in expressions Each question includes the correct answer plus an explanation of why wrong options fail — ideal for exam preparation.

Vista previa del contenido

Java OOP Advanced
Inheritance, Polymorphism, Exceptions & Collections

Advanced Java | Undergraduate CS
Questions & Verified Answers

, Java OOP Advanced — Inheritance, Polymorphism &
Collections
25 questions covering advanced Java: inheritance, polymorphism, abstract classes, interfaces,
exception handling, and ArrayList operations.


Q1. How can you prevent a class from being instantiated in Java?
A. No modifiers on the constructor
B. Use private on the constructor
C. Use static on the constructor
D. Use public on the constructor
Answer: B. Use the private modifier on the constructor.
A private constructor prevents new ClassName() from being called outside the class.
Commonly used in: Singleton pattern, utility classes with only static methods.
Note: static constructors are not allowed in Java — option C is invalid syntax.
Q2. Analyze: class TempClass { int i; public void TempClass(int j){i=j;} } — new TempClass(2).
What happens?
A. Runs fine
B. Runtime error
C. Compile error
D. Works but i is 0
Answer: C. Compile error — TempClass does not have a constructor with an int argument.
'public void TempClass(int j)' has a return type (void) → it is a METHOD, not a constructor.
A constructor has NO return type. Since no constructor is defined, Java provides only a no-arg
default.
Fix: remove 'void': public TempClass(int j) { i = j; }
Q3. What is the output when new B() is called, given: class A has a constructor that calls setI(20)
and prints 'i from A is '+i, and class B overrides setI to set i = 3*i?
A. i from A is 7
B. i from A is 60
C. i from A is 20
D. i from A is 0
Answer: B. i from A is 60
When new B() runs, A's constructor is called first.
Inside A's constructor, setI(20) is called. Due to polymorphism, B's overridden setI runs.
B's setI: i = 3 × 20 = 60. Then A's constructor prints: i from A is 60.
Key lesson: overridden methods are called polymorphically even inside superclass constructors.
Q4. When does polymorphism (dynamic binding) NOT apply in Java?
A. Overridden instance methods
B. Static methods
C. Abstract methods
D. Interface methods

Información del documento

Subido en
13 de mayo de 2026
Número de páginas
6
Escrito en
2025/2026
Tipo
Examen
Contiene
Preguntas y respuestas
$14.99

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Vendido
1
Seguidores
0
Artículos
38
Última venta
2 meses hace


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