1. What is Abstraction?
Abstraction means hiding unnecessary details and showing only important features of an object.
It focuses on what an object does instead of how it works internally.
This helps programmers manage complex programs easily.
2. What is a Class Diagram?
A Class Diagram is a graphical representation used in object-oriented design.
It shows:
- Classes
- Attributes (data)
- Methods (functions)
- Relationships between classes
It helps understand the structure of a system.
3. What is Method Overriding?
Method overriding occurs when a derived class provides its own implementation of a method that already exists in the base class.
The method must have:
- Same name
- Same parameters
- Same return type
It allows subclasses to change or extend behavior of inherited methods.
4. What is Operator Overloading?
Operator overloading means giving different meanings to the same operator depending on the type of data.
Example idea:
+can add numbers+can also join strings
So the same operator performs different operations.
5. What is Method Overloading?
Method overloading means defining multiple methods with the same name in the same class but with different parameters.
They may differ in:
- Number of parameters
- Type of parameters
This allows flexibility in using the same method name.
6. What is Polymorphism?
Polymorphism means many forms.
It allows the same function or operator to behave differently for different data types or objects.
Example idea:
- A function named
display()can work for integers, strings, or objects.
7. What is Inheritance?
Inheritance is the ability of a new class to acquire properties and methods from an existing class.
Benefits:
- Code reuse
- Easy maintenance
- Better organization
8. What is a Base Class?
A Base Class is the original class from which another class inherits properties and methods.
The new class created from it is called a Derived Class (or Subclass).
9. What is a Concrete Class?
A Concrete Class is a class that can be instantiated (objects can be created from it).
Unlike abstract classes, it contains complete implementation of methods.
10. What are Data Members?
Data Members are variables declared inside a class.
They store the data of objects and represent the state of the object.
11. What is a Constructor?
A Constructor is a special member function of a class that is automatically called when an object is created.
Its purpose is to initialize object data members.
12. What is a Destructor?
A Destructor is a special function that is automatically called when an object is destroyed.
It is used to:
- Release memory
- Clean up resources
13. What is a Global Variable?
A Global Variable is declared outside all functions.
It can be accessed anywhere in the program.
14. What is a Local Variable?
A Local Variable is declared inside a function or block.
It can only be used within that function or block.
15. What is a Null Pointer?
A Null Pointer is a pointer that does not point to any memory location.
It usually stores the value 0 or NULL.
16. What is a Pointer?
A Pointer is a variable that stores the memory address of another variable.
It allows direct access to memory.
17. What is Protected?
In a class, protected members:
- Cannot be accessed directly outside the class
- Can be accessed by derived classes
18. What is OOP?
Object-Oriented Programming (OOP) is a programming approach where programs are built using objects.
Objects contain:
- Data
- Functions
OOP hides internal implementation and exposes only necessary functionality.
19. Elements of OOP
Main elements of OOP are:
- Object
- Class
- Method
- Encapsulation
- Information Hiding
- Inheritance
- Polymorphism
20. Characteristics of OOP
Key characteristics include:
- Focus on data rather than procedures
- Programs organized into objects
- Data hiding
- Objects communicate using functions
- Easy extension of programs
- Bottom-up design approach
Question 19
Difference Between Call by Value and Call by Reference
| Call by Value | Call by Reference |
| A copy of the variable is passed | Address of the variable is passed |
| Changes inside function do not affect original variable | Changes affect the original variable |
| More memory used due to copying | Less memory used |
| Safer because original value remains unchanged | Faster but original value may change |
Question 20
Functionality of the Given BST Method
This function finds the leftmost node of a Binary Search Tree.
Explanation:
- If the tree is empty โ return NULL.
- If the left child is NULL โ current node is the smallest node.
- Otherwise โ keep moving to the left subtree recursively.
So this function returns the node with the minimum value in the BST.
Question 21
a) Declare a reference of integer i
A reference variable is declared using the & symbol.
Example idea: reference variable refers to another variable.
b) Benefits of Reference
Benefits include:
- Avoids copying of variables
- Allows functions to modify original variables
- Improves performance
- Useful in call by reference functions
References are commonly used in:
- Function parameters
- Large object passing
- Efficient memory usage
Question 22
What Does the Recursive Function Compute?
The given function computes the height of a binary tree.
Explanation:
- If the tree is empty โ return -1
- Recursively calculate:
- Height of left subtree
- Height of right subtree
- Return the larger height + 1
Therefore, the function calculates the maximum depth (height) of the binary tree.