T4Tutorials .PK

VU Past Papers CS304-Importants Questions with Answers


1. What is OOP?

Object Oriented Programming (OOP) is a programming paradigm that uses objects to design software systems.
Objects hide internal implementation details and only expose the required functionality to the user.

Example:
When riding a motorbike, we only use functions like accelerate or brake but do not know its internal mechanism.


2. Elements of OOP

Main elements of OOP are:


3. Characteristics of OOP

Key characteristics of Object-Oriented Programming:


4. Basic Concepts of OOP

Important concepts used in OOP:


5. What is an Object?

An object is an instance of a class.

It contains:

Example:
Car, Student, Bank Account etc.


6. What is Encapsulation?

Encapsulation is the process of binding data and functions into a single unit (class) and restricting direct access to some components.

Access Specifiers used:


7. What is a Class?

A class is a blueprint used to create objects.
It defines:

Example:

class Student
{
int id;
string name;

public:
void display();
};

8. What is a Meta-Class?

A Meta-Class is a class whose instances are themselves classes.
It provides services like managing methods, instances, and inheritance relationships.


9. What is Inheritance?

Inheritance is the process where one class acquires properties and behaviors of another class.

Purpose:


10. Object-Based vs Object-Oriented Programming

FeatureObject-BasedObject-Oriented
ObjectsYesYes
InheritanceNoYes
PolymorphismNoYes

Example: Ada (Object-Based)


11. What is Abstraction?

Abstraction means showing only essential information and hiding unnecessary details.

Example:
When making a phone call we only dial a number, we don’t know how network routing works.

Purpose:


12. What is a Class Diagram?

A Class Diagram is used in UML to show:


13. Method Overriding

Method overriding occurs when a derived class provides its own implementation of a method already defined in the base class.

Conditions:


14. Operator Overloading

Operator overloading allows operators such as:

+  -  ==  >  <

to behave differently depending on the data type.

Example:

Complex operator + (Complex c1, Complex c2);

15. Method Overloading

Method overloading means multiple functions with the same name but different parameters in the same class.

Example:

int sum(int a, int b);
int sum(int a, int b, int c);

16. Polymorphism

Polymorphism means “many forms”.

It allows a single interface to perform different tasks.

Types:


17. Base Class

A base class is the class whose properties are inherited by another class.

Example:

class Animal
{
};

18. Concrete Class

A concrete class is a class from which objects can be directly created.


19. Data Members

Data members are variables declared inside a class that store object data.

Example:

class Student
{
int id;
string name;
};

20. Constructor

A constructor is a special member function used to initialize objects.

Properties:

Example:

class A
{
public:
A()
{
cout<<"Constructor called";
}
};

21. Destructor

A destructor is a special function used to destroy objects and release memory.

Example:

~A()
{
cout<<"Destructor called";
}

22. Global Variable

A global variable can be accessed from any part of the program.


23. Local Variable

A local variable is declared inside a function and can only be accessed within that function.


24. Pointer

A pointer is a variable that stores the memory address of another variable.

Example:

int *ptr;

25. Null Pointer

A null pointer does not point to any valid memory location.

Example:

int *ptr = NULL;

26. Protected Keyword

The protected access specifier allows class members to be accessed:

But not outside the class.


27. Pure Virtual Function

A pure virtual function has no implementation in base class and must be overridden in derived class.

Syntax:

class A
{
public:
virtual void show() = 0;
};

28. Generic Programming

Generic programming means writing general code that works with different data types using templates.

Example:

template <class T>
T add(T a, T b)
{
return a+b;
}

29. Multiple Inheritance Problem

The Diamond Problem occurs when a class inherits from two classes that both inherit from the same base class.

This creates ambiguity.


30. Virtual Functions

Virtual functions allow runtime polymorphism.

Benefits:


31. Ternary Association

Ternary association is a relationship between three classes in UML.

Example:

Person – Insurance Policy – Contract


32. Advantages of OOP

Exit mobile version