Object Oriented Programming Through Java – Complete Answer Key
PART – A (2 Marks Questions)
1. Object-Oriented Programming organizes programs using objects containing data and methods.
Key features: Encapsulation, Inheritance, Polymorphism, Abstraction.
2. Static variables belong to class; shared among objects. Non-static belong to objects; each object
has its own copy.
3. Constructors initialize objects. Default constructor is created when no constructor is defined.
4. Overloading: same method name, different parameters. Overriding: same method name and
parameters in subclass.
5. Arrays are fixed-size; ArrayList is dynamic and resizable.
6. Interface is collection of abstract methods; supports multiple inheritance. Abstract class can have
concrete methods.
7. Wrapper classes convert primitives to objects; e.g., Integer, Float.
8. Checked exceptions checked at compile-time; unchecked at runtime.
9. sleep() pauses thread without releasing lock; wait() pauses and releases lock.
10. JDBC connects Java to databases; steps: Load driver, create connection.
PART – B (10 Marks Questions)
UNIT – I
1(a). Structure of Java Program: package declaration, import statements, class definition, main
method, variables, methods, object creation.
1(b). Control statements: if, if-else, switch; loops: for, while, do-while; jump: break, continue, return.
UNIT – II
3(a). Types of constructors: default, parameterized, copy, overloaded.
3(b). this keyword refers to current object; final keyword restricts variable, method, or class.
4(a). Overloading vs overriding: compile-time vs runtime polymorphism.
4(b). Program to read and display student details using constructor.
UNIT – III
5(a). Types of inheritance: single, multilevel, hierarchical, hybrid via interfaces.
5(b). Program implementing multiple inheritance via interfaces.
6(a). Dynamic method dispatch uses runtime polymorphism via superclass reference.
6(b). Program to find transpose of a matrix.
UNIT – IV
7(a). Packages: structure, built-in and user-defined; advantages include modularity and reuse.
7(b). Types of exceptions + try-catch-finally example.
8(a). Program to count words from a text file.
8(b). throw (explicit exception), throws (method declaration).
UNIT – V
9(a). Multithreading + program for two threads.
9(b). Synchronization ensures one thread at a time for shared resources.
10(a). String methods: length, charAt, substring, equals, compareTo.
10(b). JavaFX program with text and button click event.