JAVA OOP VIVA ANSWERS
1. Control Structures
Control structures are statements that control the flow of execution of a program.
Types: Selection (if, if-else, switch), Iteration (for, while, do-while), Jump (break, continue)
Switch:
- break terminates case
- without break → fall-through
- String allowed (Java 7), float/double not allowed
Loops:
- for → known iterations
- while → condition-based
- do-while → executes at least once
2. Class, Object, Constructor
Class = blueprint, Object = instance
Method = function inside class
this keyword → refers to current object
Encapsulation → wrapping data + methods
Constructor:
- Special method to initialize object
- Types: Default, Parameterized
- No return type
- Can be overloaded
3. Overloading, Packages, Static
Overloading → same method name, different parameters
Packages → collection of classes
Static → belongs to class, main is static so JVM can call it
4. Strings, Arrays, Vector
String → immutable
StringBuffer → mutable, thread-safe
StringBuilder → faster
Array → fixed size
ArrayList → dynamic
Vector → synchronized
5. Inheritance & Polymorphism
Inheritance → acquiring properties
Types: Single, Multilevel, Hierarchical
No multiple inheritance → avoids ambiguity
Polymorphism:
- Compile-time → overloading
- Runtime → overriding
6. Interface
Interface → collection of abstract methods
Supports multiple inheritance
No constructor
7. Multithreading
Thread → small unit of process
start() creates thread, run() executes
Synchronization avoids race condition
8. Exception Handling
Exception → runtime error
try, catch, finally, throw, throws
finally always executes
9. GUI (AWT, Swing)
AWT → basic GUI
Swing → advanced GUI
Event → user action, handled by listener
MOST IMPORTANT:
Overloading vs Overriding
Interface vs Abstract
String vs StringBuffer
Static keyword
Polymorphism → one entity many forms