100% found this document useful (1 vote)
35 views

Chapter Regression PDF

The document contains 21 questions related to object-oriented programming concepts in C++. The questions cover topics such as classes and objects, inheritance, polymorphism, encapsulation, operator overloading, streams, access modifiers, exceptions, templates, and more.

Uploaded by

elishasupreme30
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
35 views

Chapter Regression PDF

The document contains 21 questions related to object-oriented programming concepts in C++. The questions cover topics such as classes and objects, inheritance, polymorphism, encapsulation, operator overloading, streams, access modifiers, exceptions, templates, and more.

Uploaded by

elishasupreme30
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

OOPM QUESTION BANK

1. Explain the object oriented programming language with its features.


2. Discuss the role of Cout and Cin in details. Why the are used in C++ and from which class
they belong to? Explain in details.
3. Explain the characteristics of object- oriented programming and procedural programming
in brief.
4. Describe the various control statement with example.
5. What are empty classes? Can instance empty class be created? Give reason.
6. Explain the concept of association an aggregation in object oriented approach? What is
abstract class? Why abstract class are used.
7. What do you mean by array index out of bound exception and null pointer exception?
8. What is member function? Explain with example.
9. What is operator overloading? Can friend function be used to overload the assignment
operator (=).
10. Write the program in C++ which is demonstrate the use of inheritance.
11. Explain the pointer and function pointer.
12. What are the advantage and limitation of using default arguments in a function? Write the
program which defines a function with three default arguments and call the function in
four different ways.
13. What are the various stream classes and stream error? Explain them in brief. What are
input and output stream? Give example.
14. What are the access modifies? How many type of access modifier are available in C++ ?
explain each of them and their role in implemented the data hiding in object oriented
programming.
15. How inherited method is different form redefined method?
16. Explain in details about exception and how they handled? Define function template and
class template.
17. Create a class called cake with attribute heights, weight, shape and massage with default
constructor. Overload the constructor with arguments. Create method to display details
and increase the height by 2cms and weight by 0.5 kg. Finally display the details again.
18. How message passing is possible in JAVA? Give example.
19. Explain ATM system using object oriented diagram.
20. Hoe polymorphism is achieved at complier time and run time?
21. Write short notes on:
i. New and Delete
ii. Abstract base classes
iii. Virtual function and pure virtual function
iv. Static member
ANSWER 1. Features Of Object Oriented Programming

The main features of object oriented programming are as follows:


Classes
Objects
Abstraction
Polymorphism
Inheritance
Encapsulation

In the upcoming sections, let’s see each object-oriented programming feature in detail.
Classes and Objects in OOPs
A class is a template that consists of the data members or variables and functions and defines
the properties and methods for a group of objects.
The compiler does not allocate memory whenever you define a class.
Example:
You can define a class called Vehicle. Its data fields can be vehicle_name, model_number,
color, date_of_manufacture, etc.

An object is nothing but an instance of a class. Each object has its values for the
different properties present in its class. The compiler allocates memory for each object.
Example:
The different objects of the class Vehicle can be Car, Bike, Bicycle, etc. Each of them will
have its values for the fields like color, model_number, etc.
Abstraction
The literal meaning of abstraction is to remove some characteristics from something to
reduce it to a smaller set. Similarly, Object Oriented Programming abstraction exposes only
the essential information of an object to the user and hides the other details.
In real life, like when you toggle a switch, it simply turns on or off the lights. Here, we only
know the functionality of the switch, but we don’t know its internal implementation, like how
it works.
How to implement abstraction?
You can implement abstraction using classes that group the data members and function
together. Inside classes, you can choose the access specifiers for its members to control how
they are visible to the outside world. We can also create header files containing the
implementations of all the necessary functions. So, you can include the header file and call
these functions without getting into their implementation.
Advantages of Abstraction
The advantages of abstraction are as follows:
It enables code reuse by avoiding code duplication.

It enhances software security by making only necessary information available to the users
and hiding the complex ones.
Inheritance
Inheritance is one of the most important features of object oriented programming. It allows a
class to inherit the properties and methods of another class called the parent class, the base
class, or the super-class.
The class that inherits is called the child class or sub-class.
It helps to avoid duplication of codes by allowing code reuse as you need not define the same
methods and properties present in a super-class in the sub-classes again. The sub-class can
simply inherit them.

Example:
You can have a parent class called “Shape” and other classes like Square, Circle, Rectangle,
etc. Since all these are also shapes, they will have all the properties of a shape so that they
can inherit the class Shape.
Polymorphism
The word polymorphism means to have many forms. So, by using polymorphism, you can
add different meanings to a single component.
There are two types of polymorphism:
 Run-time polymorphism
 Compile-time polymorphism

Let's see each type in the next section.


Method Overloading
Methods overloading is a type of compile-time polymorphism using which you can define
various functions with the same name but different numbers of arguments. The function call
is resolved at compile time, so it's a type of compile-time polymorphism. Here resolution of
the function call implies binding to the correct function definition depending on the
arguments passed in the function call.
Example:
You can create a function “add”. Now, when you pass two integers to this function, it will
return their sum, while on passing two strings, it will return their concatenation.
So, the same function acts differently depending on the input data type.
Method Overriding
Method Overriding is a type of run-time polymorphism. It allows overriding a parent class’s
method by a child class. Overriding means that a child class provides a new implementation
of the same method it inherits from the parent class.
These function calls are resolved at run-time, so it's a type of runtime polymorphism.
Example:
You can have a parent class called “Shape” with a method named “findArea” that calculates
and returns the area of the shape. Several sub-classes inherit from the “Shape,” like Square,
Circle, Rectangle, etc. Each of them will define the function “findArea” in its way, thus
overriding the function.
Encapsulation
Encapsulation means enclosing the data/variables and the methods for manipulating the data
into a single entity called a class. It helps to hide the internal implementation of the functions
and state of the variables, promoting abstraction.

Example:
You can have some private variables in a class that you can't access outside the class for
security reasons. Now, to read or change the value of this variable, you can define public
functions in the class which will perform the read or writes operations.
Know What is Object in OOPs here in detail.
Other Oops Features:
Dynamic Binding
Dynamic binding takes place during run time based on the type of object. Since it is delayed
till the run time, it is also called late binding or runtime binding. When the compiler cannot
determine all the information required to resolve a function call during compile time, these
function calls are not bound until run time.
Message Passing
Message passing refers to the process of passing a message, or data, between different objects
or components in a program. This can be done in many ways, such as function calls, events,
or inter-process communication. The specific implementation of message passing will depend
on the program's design and the system's needs.

Advantages of Object Oriented Programming


 It makes troubleshooting easier and faster by making the code modular. So, you can
look at the particular class or method whenever an error occurs instead of checking
the entire code.
 It allows code reuse by inheritance.
 It enables flexibility through polymorphism as one function or object can adapt to
several forms according to the requirement.
 It allows you to solve a problem efficiently by breaking a huge problem into smaller
manageable parts like classes and objects.
Disadvantages of Object Oriented Programming
It has a steep learning curve because breaking down a problem into simple components
requires long-term thinking, which comes with experience.

You might also like