Charuccc Merged
Charuccc Merged
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.
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.
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 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.
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
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>