Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
Document preview thumbnail
Voorbeeld 2 van de 6 pagina's
Tentamen (uitwerkingen)

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

Document preview thumbnail
Voorbeeld 2 van de 6 pagina's

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.

Voorbeeld van de inhoud

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

Documentinformatie

Geüpload op
13 mei 2026
Aantal pagina's
6
Geschreven in
2025/2026
Type
Tentamen (uitwerkingen)
Bevat
Vragen en antwoorden
$14.99

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kan je een ander document kiezen. Je kan het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF

Verkocht
1
Volgers
0
Items
38
Laatst verkocht
2 maanden geleden


Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via Bancontact, iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo eenvoudig kan het zijn.”

Alisha Student

Bezig met je bronvermelding?

Maak nauwkeurige citaten in APA, MLA en Harvard met onze gratis bronnengenerator.

Bezig met je bronvermelding?

Veelgestelde vragen