Chapter 5
Object-Oriented Programming
NEB Class 12 past exam questions
Past questions and answers
13 questions set from this chapter. Most repeated first.
- 2083 Baishakh · 1 mark
Which of the following feature allows the same method name to be used for different types/number of parameters in OOPs concept?
(a) Abstraction
(b) Encapsulation
(c) Polymorphism
(d) Inheritance
Answer
(c) Polymorphism
Polymorphism (specifically compile-time polymorphism through method overloading) allows the same method name to be defined more than once with a different number or type of parameters.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 1 MCQ
Loading…
- 2083 Baishakh · 1+4 marks
What is OOP (Object Oriented Programming)? Describe any four features of OOP.
Answer
OOP (Object Oriented Programming) is a programming paradigm that organises a program around objects — self-contained units that bundle together data (attributes) and the functions (methods) that operate on that data — rather than around procedures or functions alone. A program is built by defining classes (blueprints) and creating objects (instances) from them. C++, Java, Python and C# are common OOP languages.
Four features of OOP:
-
Encapsulation — Wrapping data and the methods that manipulate it into a single unit (class), and hiding the internal data from outside access using access specifiers like
private. Only the class's own public methods can touch the hidden data. This protects data from accidental modification and keeps the code secure and easy to maintain. For example, aBankAccountclass keepsbalanceprivate and allows changes only throughdeposit()andwithdraw(). -
Inheritance — The ability of one class (the derived/child class) to acquire the properties and methods of another class (the base/parent class). This promotes code reusability and establishes an "is-a" relationship. For example, a
Carclass can inherit the common propertiesname,modeland methodstart()from aVehicleclass instead of rewriting them. -
Polymorphism — The ability of the same function or operator to behave differently in different contexts. It is achieved through function overloading (same name, different parameter lists, resolved at compile time) and function overriding (a child class redefines a base class method, resolved at run time). For example,
area()can compute the area of a circle or a rectangle depending on the arguments passed. -
Abstraction — Hiding the complex implementation details and exposing only the essential features to the user. The user knows what an object does without knowing how it does it. For example, while driving a car we use the steering and brakes without knowing their internal mechanism; in programming, abstract classes and interfaces provide this.
(Other valid features: data hiding, message passing, dynamic binding, reusability.)
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2082 Supplementary · 1 mark
What is the primary benefit of using inheritance in oop ?
(a) Code reusability
(b) Error correction
(c) Design pattern
(d) Debugging
Answer
(a) Code reusability
Inheritance lets a new class (subclass) acquire the properties and methods of an existing class (superclass), so the common code is written once and reused instead of being rewritten in every class.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 1 MCQ
Loading…
- 2082 Supplementary · 5 marks
Write short notes on "class" and "Polymorphism" in Object Oriented programming.
Answer
Class
A class is a blueprint or template in Object Oriented Programming that defines the properties (data members) and behaviours (member functions) common to all objects of a certain kind. It does not itself occupy memory for data; memory is allocated only when an object of the class is created.
A class typically contains:
- Data members — variables that hold the state of an object.
- Member functions (methods) — functions that define what an object can do.
- Access specifiers —
private,public, andprotected, which control the visibility of members. By default, members of a class areprivate, which enforces data hiding (encapsulation).
Syntax (C++):
class Student {
private:
int roll;
char name[20];
public:
void getData() { cin >> roll >> name; }
void showData() { cout << roll << " " << name; }
};
Here Student is a class; roll and name are data members; getData() and showData() are member functions. An object is created as Student s1;, and its members are accessed as s1.getData();.
Key points:
- A class is a user-defined data type; an object is a variable of that type.
- It binds data and the functions that operate on that data into a single unit (encapsulation).
- It supports the other OOP features — abstraction, inheritance, and polymorphism.
Polymorphism
Polymorphism (Greek: poly = many, morph = forms) is the ability of the same function, operator, or object to behave differently in different contexts. It lets a single interface represent different underlying implementations, which makes a program flexible and extensible.
Polymorphism is of two types:
1. Compile-time polymorphism (static binding) — the function to be called is decided by the compiler.
- Function overloading: two or more functions with the same name but different parameter lists.
int area(int s) { return s * s; } // square
int area(int l, int b) { return l * b; } // rectangle
- Operator overloading: giving an existing operator an extra meaning for a user-defined type, e.g. overloading
+to add two objects of aComplexclass.
2. Run-time polymorphism (dynamic binding) — the function to be called is decided at run time.
- Achieved through virtual functions and inheritance. A base-class pointer can point to a derived-class object, and the call is resolved at run time by the virtual function mechanism.
class Shape {
public: virtual void draw() { cout << "Shape"; }
};
class Circle : public Shape {
public: void draw() { cout << "Circle"; }
};
// Shape *p = new Circle(); p->draw(); // prints "Circle"
Advantages:
- Code reusability and a single interface for many forms.
- Programs become easier to extend — new derived classes can be added without changing existing code.
- It is the mechanism behind dynamic method dispatch in languages such as C++ and Java.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2082 Baishakh · 1 mark
In which of the following programming, the emphasis is given on data rather than on procedures?
(a) Procedural programming
(b) Structural programming
(c) Object-oriented programming
(d) Declarative programming
Answer
(c) Object-oriented programming
In OOP the data (objects and their attributes) is the centre of program design, and the procedures (methods) are built around and bound to that data, whereas procedural and structural programming focus on the sequence of procedures or functions.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 1 MCQ
Loading…
- 2082 Baishakh · 5 marks
Write short notes on class and inheritance in OOP with example.
Answer
Class
A class is a blueprint or template that defines the properties (data members) and behaviours (member functions) common to a set of objects. It does not itself occupy memory for data; memory is allocated only when an object of the class is created. A class binds data and the functions that operate on that data into a single unit — this is the principle of encapsulation.
Syntax:
class ClassName {
private:
// data members
public:
// member functions
};
Example:
class Student {
private:
int roll;
float marks;
public:
void getData(int r, float m) {
roll = r;
marks = m;
}
void showData() {
cout << "Roll: " << roll << ", Marks: " << marks;
}
};
int main() {
Student s1; // s1 is an object of class Student
s1.getData(10, 85.5);
s1.showData();
}
Here Student is the class, while s1 is an object (instance) of that class. The data members roll and marks are hidden from outside access, and can be used only through the public member functions.
Inheritance
Inheritance is the mechanism by which one class (the derived or child class) acquires the properties and behaviours of another class (the base or parent class). It supports reusability — the common features are written once in the base class and reused by derived classes — and establishes an "is-a" relationship between classes. It also allows the derived class to add its own members or to override inherited behaviour, which is the basis of runtime polymorphism.
Syntax:
class Derived : visibility Base {
// additional members
};
Example:
class Person { // base class
protected:
string name;
public:
void setName(string n) { name = n; }
void showName() { cout << "Name: " << name << endl; }
};
class Employee : public Person { // derived class
private:
float salary;
public:
void setSalary(float s) { salary = s; }
void showSalary() { cout << "Salary: " << salary; }
};
int main() {
Employee e;
e.setName("Ramesh"); // inherited from Person
e.setSalary(45000); // own member
e.showName();
e.showSalary();
}
Here Employee inherits name, setName() and showName() from Person without rewriting them, and adds its own salary member. This shows how inheritance promotes code reuse and hierarchical classification of objects.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2081 Baishakh · 1 mark
Which OOP feature allows a class to inherit properties and behavior from another class?
(a) Inheritance
(b) Encapsulation
(c) Polymorphism
(d) Abstraction
Answer
(a) Inheritance
Inheritance is the OOP feature in which a derived (child) class acquires the properties and behaviours of an existing base (parent) class. Encapsulation hides data, polymorphism lets one interface take many forms, and abstraction hides implementation details.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 1 MCQ
Loading…
- 2081 Baishakh · 5 marks
Write short note on class and object in OOPs with a real-world example.
Answer
Class and Object in OOP
Class
A class is a user-defined blueprint or template that defines the properties (data members) and behaviours (member functions/methods) that its objects will have. It does not occupy memory for data until an object is created. It groups data and the functions that operate on that data into a single unit, which is the basis of encapsulation.
Object
An object is a real, physical instance of a class. When an object is created, memory is allocated for its data members, and it can use the methods defined in the class. Each object has its own copy of the data members, so different objects of the same class can hold different values.
Key points
- A class is a logical entity; an object is a physical entity.
- A class is declared once; many objects can be created from it.
- Objects are created using the
newkeyword (in Java/C++) or directly (in C++). - Class = data + methods; object = actual values + ability to call those methods.
Real-world example
Consider a Student class. The class defines data members such as name, rollNo, and marks, and methods such as display() and calculateGrade(). This is only a template. When we create objects like student1 (Rita, roll 5, 480 marks) and student2 (Hari, roll 6, 450 marks), each object holds its own values but uses the same methods. Thus the class describes what a student is, while each object represents an actual student.
class Student {
String name;
int rollNo;
float marks;
void display() {
System.out.println(name + " " + rollNo + " " + marks);
}
}
class Main {
public static void main(String[] args) {
Student s1 = new Student(); // object 1
s1.name = "Rita"; s1.rollNo = 5; s1.marks = 480;
Student s2 = new Student(); // object 2
s2.name = "Hari"; s2.rollNo = 6; s2.marks = 450;
s1.display();
s2.display();
}
}
Here Student is the class and s1, s2 are objects.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2080 Supplementary · 1 mark
Which concept allows you to reuse the written code in OOPs?
(a) Encapsulation
(b) Inheritance
(c) Polymorphism
(d) Class
Answer
(b) Inheritance
Inheritance lets a new class (derived/sub) acquire the properties and methods of an existing class (base/super), so the already-written code is reused without rewriting it.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 1 MCQ
Loading…
- 2080 Supplementary · 5 marks
Describe the inheritance concept with an example.
Answer
Inheritance
Inheritance is the object-oriented programming feature by which a new class (called the derived class, subclass, or child class) acquires the properties (data members) and behaviours (member functions) of an existing class (called the base class, superclass, or parent class). The derived class automatically gets all the members of the base class and can additionally define its own members or modify (override) the inherited ones.
Key points:
- It establishes an "is-a" relationship between classes — e.g., a Dog is an Animal.
- It promotes code reusability, since common members are written once in the base class and reused by all derived classes.
- The derived class can extend the base class by adding new members, or override inherited functions to give them new behaviour.
- It supports hierarchical classification of objects and is the basis of polymorphism.
- Access to inherited members depends on the access specifier:
privatemembers of the base class are not directly accessible in the derived class, whilepublicandprotectedmembers are.
Syntax (C++):
class Base { ... };
class Derived : access_specifier Base { ... };
Example:
#include <iostream>
using namespace std;
class Animal { // base class
public:
void eat() {
cout << "This animal eats food." << endl;
}
};
class Dog : public Animal { // derived class
public:
void bark() {
cout << "The dog barks." << endl;
}
};
int main() {
Dog d;
d.eat(); // inherited from Animal
d.bark(); // own member of Dog
return 0;
}
Output:
This animal eats food.
The dog barks.
Here the object d of the derived class Dog can call eat(), even though eat() is defined in the base class Animal. This shows that Dog has inherited the property of Animal and has added its own feature bark(). In this way, inheritance lets us build specialised classes on top of general ones while reusing existing code.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2080 Baishakh · 5 marks
How is even-driven program (or OOP) differing from procedural-oriented programming? Explain.
Answer
Event-driven programming vs procedural-oriented programming
Procedural-oriented programming (POP) is a programming approach in which a program is written as a sequence of instructions grouped into procedures or functions. The program itself decides the order in which statements execute — it follows a top-down, step-by-step flow. The programmer controls when each function runs. Examples: C, Pascal, FORTRAN.
Event-driven programming is an approach in which the flow of the program is decided by events — actions such as a mouse click, a key press, a button press, or a timer — rather than by a fixed sequence. The program waits in an event loop; when an event occurs, the corresponding event handler (procedure) is triggered and runs. Examples: Visual Basic, JavaScript, and most GUI applications.
Main differences:
| Basis | Procedural-oriented programming | Event-driven programming |
|---|---|---|
| Flow of control | Determined by the programmer, top to bottom | Determined by events triggered by the user or system |
| Execution order | Fixed sequence of statements | Order is unpredictable; depends on which event occurs |
| Program structure | Built around procedures/functions | Built around event handlers and a main event loop |
| User interaction | Limited; program runs to completion on its own | High; program responds to user actions |
| Waiting state | Program does not wait for input except at read statements | Program waits in an event loop for the next event |
| Suited for | Batch processing, mathematical and scientific programs | GUI applications, games, web pages, mobile apps |
Example: In POP, a program to add two numbers runs as: read first number → read second number → add → display. In event-driven programming, the same form has a "Calculate" button; the addition code runs only when the user clicks that button. If the user never clicks, the code never executes.
In short, POP is programmer-controlled and sequential, while event-driven programming is event-controlled and interactive.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
- 2079 Jestha · 1 mark
Which feature of OOP is illustrated the code reusability?
(a) Polymorphism
(b) Abstraction
(c) Encapsulation
(d) Inheritance
Answer
(d) Inheritance
Inheritance lets a new class reuse the properties and methods of an existing class without rewriting them, so it directly provides code reusability.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 1 MCQ
Loading…
- 2079 Jestha · 5 marks
- NEB Class 12 Computer Science · 5 marks
Compare the OOPs and procedural programming language.
Answer
Comparison of OOPs and Procedural Programming Language
Object-Oriented Programming (OOP):
- Basis: Program is organized around objects — a combination of data (attributes) and functions (methods) that operate on that data.
- Data security: Data is hidden inside classes using access specifiers (private, protected, public). This is called data encapsulation, so data cannot be accessed directly from outside the class.
- Approach: Follows a bottom-up approach — first the objects/classes are designed, then they are combined to build the complete program.
- Reusability: Supports inheritance, so an existing class can be extended to create a new class. This gives high code reusability.
- Program structure: Program is divided into classes and objects, and the program logic is written inside methods of the class.
- Data movement: Data can move freely between methods of the same class, and methods of one object can access data of another object through a proper interface.
- Examples: C++, Java, Python, C#, PHP.
Procedural Programming Language:
- Basis: Program is organized around functions/procedures — a sequence of instructions to be executed step by step.
- Data security: Data is not hidden; variables are usually global or local and can be accessed by any function, so there is little data security.
- Approach: Follows a top-down approach — the main problem is divided into smaller sub-problems (functions).
- Reusability: Limited reusability. Functions can be reused, but there is no concept of inheritance to extend existing code.
- Program structure: Program is divided into functions, and the main function calls these functions in order.
- Data movement: Data moves openly from one function to another through parameters and global variables.
- Examples: C, FORTRAN, COBOL, Pascal, BASIC.
Key differences at a glance:
| Feature | OOP | Procedural |
|---|---|---|
| Unit of program | Object | Function |
| Approach | Bottom-up | Top-down |
| Data hiding | Yes (encapsulation) | No |
| Inheritance | Supported | Not supported |
| Polymorphism | Supported | Not supported |
| Security | High | Low |
| Emphasis | Data | Procedure/algorithm |
Conclusion: Procedural programming is simple and suitable for small, straightforward programs, while OOP is more secure, reusable, and easier to maintain, so it is preferred for large and complex software systems.
Answer checked by Claude Sonnet · Oct 21, 2026
Test yourself · 2 MCQs
Loading…
Questions from NEB Class 12 2083 Computer Science (Board exam, Baishakh 2083; typed transcription), NEB Class 12 2082 Supplementary Computer Science (Supplementary exam 2082; set B; scanned images), NEB Class 12 2082 Computer Science (Board exam, Baishakh 2082; set D; typed transcription), NEB Class 12 2081 Computer Science (Board exam, Baishakh 2081; typed transcription), NEB Class 12 2080 Supplementary Computer Science (Supplementary/grade-increment exam 2080; set B; typed transcription), NEB Class 12 2080 Computer Science (Board exam, Baishakh 2080; typed text (solved)), NEB Class 12 2079 Computer Science (Board exam, Jestha 2079; set A; typed transcription) and NEB Class 12 Computer Science (4281) Model Question (NEB model question set, 50 marks, 2 hours; questions only (answers not taken). Wording of some questions reconstructed from a page summary, so check against the paper.). Answers are written for this site; check them against your class notes.
Chapter titles and hours from the official syllabus ↗