0% found this document useful (0 votes)
33 views

Charuccc Merged

Ghg

Uploaded by

charudatta patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

Charuccc Merged

Ghg

Uploaded by

charudatta patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

2.

) What is object-oriented programming

Object-Oriented Programming (OOP) is a programming paradigm based on the concept of


"objects", which can contain data and code. The data is in the form of fields (often known as
attributes or properties), and the code is in the form of procedures (often known as methods). A
common feature of objects is that procedures (or methods) are attached to them and can access
and modify the object's data fields. In this brand of OOP, there is usually a special name such as
this or self used to refer to the current object. In OOP, computer programs are designed by
making them out of objects that interact with one another.

3)Explain the encapsulation? Explain any two Access Specifiers.

Encapsulation: o Encapsulation is defined as the wrapping up of data under a single unit. It is the
mechanism that binds together code and the data it manipulates. o In OOP, you wrapping the
code into a single unit where you can determine the scope of each piece of data.

Differentiate between Structured and Object oriented programming?

Parameter Object Oriented Programming Procedural Programming

Access In OOPs access modifiers are No such modifiers are introduced in


modifiers introduced namely as Private, procedural programming.
Public, and Protected.

Security Due to abstraction in OOPs data Procedural programming is less secure


hiding is possible and hence it is as compare to OOPs.
more secure than POP.

Program OOP divides a program into small Procedural programming divides a


division parts and these parts are referred to program into small programs and each
as objects. small program is referred to as a
function.

Importance OOP gives importance to data rather Procedural programming does not give
than functions or procedures. importance to data. In POP, functions
along with sequence of actions are
followed.

Inheritance OOP provides inheritance in three Procedural programming does not


modes i.e. protected, private, and provide any inheritance.
public
Examples C++, C#, Java, Python, etc. are the C, BASIC, COBOL, Pascal, etc. are the
examples of OOP languages. examples POP languages.

What is function? Explain inline function with example?

Abstraction: Data Abstraction is the property by virtue of which only the essential details are
displayed to the user. The trivial or the non-essentials units are not displayed to the user. By
using classes, you are able to generalize your object types, simplifying your program. Inheritance:
because a class can inherit attributes and behaviors from another class, you are able to reuse
more code. Inheritance is the mechanism in which one class is allowed to inherit the features
(fields and methods) of another class. Polymorphism: Polymorphism refers to the ability of OOPs
programming languages to differentiate between entities with the same name efficiently.

1) List and explain any 3 characteristics of object-oriented programming?


Abstraction: Data Abstraction is the property by virtue of which only the essential details are
displayed to the user. The trivial or the non-essentials units are not displayed to the user. By
using classes, you are able to generalize your object types, simplifying your program.
Inheritance: because a class can inherit attributes and behaviors from another class, you are
able to reuse more code. Inheritance is the mechanism in which one class is allowed to
inherit the features (fields and methods) of another class.
Polymorphism: Polymorphism refers to the ability of OOPs programming languages to
differentiate between entities with the same name efficiently.

What is function? Explain inline function with example?


Function A function is a code segment or a block of code defined to accomplish a specific
purpose. A function is often designed to spare the user from repeatedly writing the same
lines of code for the same input. All the lines of code are combined into a single function that
may be invoked from anywhere. Every C++ application includes a default function called
main().The function also has a return type, which is used to specify the type of data the
function would return when its execution is complete. The function's return type could be
any data type, including the void, which states that there is no need to return anything once
the execution of that function is complete.

What is a class? Explain the declaration of a class in brief?


Class A Class is a C++ building piece that leads to Object-Oriented programming. It's a user
defined data type with its own set of data members and member functions that can be
accessed and used by establishing a class instance. A class defines the blueprint for a data
type. In the above example, the scaler is the name of the class. We can include the data
members, which are the class variables. Similarly, member functions are added to the class;
for example, print_name(), here is the member function, and student_name is the data
member. Here, the student1 and student2 are the class scaler objects.
What is a constructor and destructor? Explain types of constructors?

What is a Constructor in C++? A Constructor is a special member function of a class and shares the
same name as of class, which means the constructor and class have the same name. Constructor is
called by the compiler whenever the object of the class is created. It allocates the memory to the
object and initializes class data members by default values or values passed by the user while
creating an object. Constructors don’t have any return type because their work is to just create and
initialize an object.

Desstructor: A destructor is a member function that is invoked automatically when the object goes
out of scope or is explicitly destroyed by a call to delete. A destructor has the same name as the
class, preceded by a tilde (~). For example, the destructor for class cube is declared: ~cube(). If you
don't define a destructor, the compiler provides a default one; for many classes this is sufficient. You
only need to define a custom destructor when the class stores handles to system resources that need
to be released, or pointers that own the memory they point to.

Explain Copy Constructor

Copy Constructor: Copy constructors are the member functions of a class that initialize the data
members of the class using another object of the same class. It copies the values of the data
variables of one object of a class to the data members of another object of the same class.
1) Define Virtual base class.?
Virtual classes are primarily used during multiple inheritance. To avoid, multiple instances of
the same class being taken to the same class which later causes ambiguity, virtual classes are
used.
2) What is visibility mode? What are the different types of visibility modes ?
The visibility mode specifies whether the features of the base class are publicly inherited
privately inherited. It can be public or private
There are 3 visibility mode in c++
Pablic Mode: If we derive a subclass from a public buse class. Then the public member of the
base class will become public in the derived class and protected members of the base class
will become protected in the derived claus
Protected Mode: If wy derive a subclass from a Protected base class. Then both public
members and protected members of the base class will become protected in the derived
class
Private Mode: If we derive a subclass from a Private buse class. Then both public members
and protected members of the base class will become Private in the derived class.
3) What are the different types of inheritance supported by C++? Explain each with an
example.?
1 Single inheritance
2 Multilevel inheritance
3 Multiple inheritance
4 Hierarchical inheritance
5. Hybrid inheritance
Single Inheritance:
In single inheritance, a class is allowed to inherit from only one class. Le one subclass is
inherited by one hase class only

4) Explain the Unary operator overloading


Unary operators overloaded by member functions take no formal arguments, whereas Wa
they are overloaded by friend functions they take a single argument.
Unary operators operate on only one operand. The increment operator and decrem operator
are examples of unary operators.

What is operator overloading? Explain the importance of operator rules for operator
overloading?
C++ has the ability to provide the operators with a special meaning for a data type, this
ability s known as operator overloading.
Operator overloading is a compile-time polymorphism. It is an idea of giving special meaning
to an existing operator in C without changing its original meaning For example, we can
overload an operator + in a class like String so that we can concatenate two strings by just
using
The advantage of Operator overloading is to perform different operations on the same
operand
Explain the Binary operator overloading ? using Friend Function?
Binary Operator Overloading:
Binary operators overloaded by means of member functions take one formal argument
which is the value to the right
Operators overloading using friend function :
#include<iostream.h>
using namespace std;
class A
{
private:
int a;
public:
void set_a();
void get_a();

What are virtual functions? Describe the rules for declaring virtual functions?
Virtual Function:
A virtual function is a member function in the base class that we expect to redefine in derive
classes. It is declared using the virtual keyword.
Template
When the function is made virtual, C++ determines which function is to be invoked at the
runtime based on the type of object pointed by the base class pointer.
Rules of Virtual Function:
• Virtual functions must be members of some class.
• Virtual functions cannot be static members.
• They are accessed through object pointers.

What do you mean by exception handling? How exceptions are handled in C++.?
such as disc failure, keyboard interrupts etc.). C++ provides the following specialized
keywords for this purpose:
try: Represents a block of code that can throw an exception.
catch: Represents a block of code that is executed when a particular exception is thrown.
throw: Used to throw an exception. Also used to list the exceptions that a function throws
but doesn't handle itself.
Write the significance of pure virtual functions in C++
Pure Virtual Functions:ssss
A virtual function is not used for performing any task. It only serves as a placeholder
When the function has no definition, such function is known as "do-nothing" function.
The "do-nothing" function is known as a pure virtual function. A pure virtual function is a
inction declared in the base class that has no definition relative to the base class. A class
containing the pure virtual function cannot be used to declare the objects of its own. nuch
classes are known as "abstract base classes".
The main objective of the base class is to provide the traits to the derived classes and to
create the base pointer used for achieving the runtime polymorphism>

You might also like