T4Tutorials .PK

VU Past Papers CS301 – Midterm Questions Solved

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:

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:

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:

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:

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:

7. What is Inheritance?

Inheritance is the ability of a new class to acquire properties and methods from an existing class.

Benefits:

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:

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:

18. What is OOP?

Object-Oriented Programming (OOP) is a programming approach where programs are built using objects.

Objects contain:

OOP hides internal implementation and exposes only necessary functionality.

19. Elements of OOP

Main elements of OOP are:

  1. Object
  2. Class
  3. Method
  4. Encapsulation
  5. Information Hiding
  6. Inheritance
  7. Polymorphism

20. Characteristics of OOP

Key characteristics include:

Question 19

Difference Between Call by Value and Call by Reference

Call by ValueCall by Reference
A copy of the variable is passedAddress of the variable is passed
Changes inside function do not affect original variableChanges affect the original variable
More memory used due to copyingLess memory used
Safer because original value remains unchangedFaster 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:

  1. If the tree is empty → return NULL.
  2. If the left child is NULL → current node is the smallest node.
  3. 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:

References are commonly used in:

Question 22

What Does the Recursive Function Compute?

The given function computes the height of a binary tree.

Explanation:

  1. If the tree is empty → return -1
  2. Recursively calculate:
    • Height of left subtree
    • Height of right subtree
  3. Return the larger height + 1

Therefore, the function calculates the maximum depth (height) of the binary tree.

Exit mobile version