OOP is tested because it is both a programming technique and a design approach. PSC questions often ask definitions, comparison with structured programming, inheritance types, polymorphism, binding, encapsulation and real software modeling.
Engineering Definitions
Class
Standard definition: A blueprint that defines data members and methods for objects.
Exam meaning: Object बनाउन प्रयोग हुने data र behavior को template।
Object
Standard definition: A runtime instance of a class with identity, state and behavior.
Exam meaning: Class बाट बनेको actual entity जसमा state र methods हुन्छन्।
Encapsulation
Standard definition: Bundling data with methods and restricting direct access to internal representation.
Exam meaning: Data र method एउटै unit मा राखेर direct access control गर्ने principle।
Inheritance
Standard definition: A mechanism where one class derives properties and behavior from another class.
Exam meaning: Existing class बाट नयाँ class ले features reuse/extend गर्ने mechanism।
Polymorphism
Standard definition: The ability of the same interface/message to behave differently for different object types.
Exam meaning: Same method/interface ले object type अनुसार फरक behavior दिनु।
Concept Teaching
OOP should be explained through modeling. A class defines common structure, objects represent real entities, encapsulation protects invariants, inheritance expresses “is-a” relationship, and polymorphism allows code to depend on interface rather than concrete class.
Core OOP Principles
The four pillars are commonly asked.
- Abstraction hides unnecessary detail and exposes essential behavior.
- Encapsulation protects data through access control.
- Inheritance supports reuse and specialization.
- Polymorphism supports flexible behavior through common interface.
- Message passing means objects interact through method calls.
Inheritance and Relationships
Not every reuse should be inheritance.
| Relationship | Meaning | Example |
|---|---|---|
| Is-a | Inheritance/specialization | SavingsAccount is an Account |
| Has-a | Composition/aggregation | Car has Engine |
| Uses-a | Dependency | Service uses Repository |
| Part-of | Composition with ownership | Order has OrderItems |
Polymorphism and Binding
Polymorphism is high-yield for MCQ and subjective answers.
- Compile-time polymorphism often uses function/operator overloading.
- Run-time polymorphism uses overriding and dynamic dispatch.
- Static binding resolves call at compile time.
- Dynamic binding resolves method at runtime based on actual object type.
- Abstract class/interface enables programming to contract.
Access Control and Encapsulation
Access modifiers protect internal state.
- Public members are accessible from outside.
- Private members are accessible only inside class.
- Protected members are accessible in class and subclasses in many languages.
- Getters/setters should preserve validation, not blindly expose fields.
- Encapsulation reduces ripple effects from internal changes.
Engineering Mechanism
- Program defines classes with fields and methods.
- Objects are created with state in memory.
- Method calls operate on object state.
- Inheritance builds derived class behavior from base class.
- Dynamic dispatch selects overridden method at runtime.
- Encapsulation controls access to state.
Diagrams / Models To Draw
- Draw class diagram with attributes and methods.
- Draw inheritance hierarchy.
- Draw composition has-a relationship.
- Draw dynamic dispatch from base reference to derived object.
Formulas, Algorithms and Code Patterns
- OOP design rule: prefer composition when is-a relationship is weak.
- Runtime polymorphism = overriding + dynamic binding.
- Encapsulation = data + behavior + access control.
- Liskov idea: subclass should be substitutable for base type.
| Concept | Purpose | Exam trap |
|---|---|---|
| Class | Blueprint | Not runtime object |
| Object | Instance | Has identity/state |
| Encapsulation | Information hiding | Not just using class |
| Inheritance | Reuse/specialization | Can create tight coupling |
| Overloading | Same name different signature | Compile-time |
| Overriding | Subclass changes behavior | Runtime polymorphism |
Exam Point
- Use real examples for OOP answers.
- Differentiate overloading and overriding.
- Do not equate encapsulation with abstraction.
- Mention dynamic binding for runtime polymorphism.
- Inheritance should model is-a relation.
Worked Example
If `Shape` defines `draw()` and `Circle` and `Rectangle` override it, a list of Shape references can call draw on each object. At runtime, Circle draws a circle and Rectangle draws a rectangle. This is runtime polymorphism.
Subjective Answer Pattern
- Define OOP.
- Explain class/object.
- Discuss encapsulation and abstraction.
- Explain inheritance and polymorphism.
- Compare overloading vs overriding.
- Add advantages, limitations and example.
Common Engineering Mistakes
- Saying class and object are same.
- Using inheritance for has-a relationship.
- Confusing overloading and overriding.
- Ignoring access modifiers.
- Claiming OOP always improves design automatically.
MCQ Revision
- What is dynamic binding?
- What is overriding?
- Which relationship should inheritance represent?
- What does private access mean?
- What is encapsulation?
- What is object identity?
Final Summary
- OOP models software using objects and interactions.
- Encapsulation protects object state.
- Inheritance supports is-a specialization.
- Polymorphism enables flexible interface-based code.
- Good OOP design balances reuse with coupling control.