You are on page 1of 11

1.What is class?

Ans: A class in C++ is a user-defined type or data


structure declared with keyword  class  that has data and
functions (also called member variables and member
functions) as its members whose access is governed by the
three access specifiers private, protected or public. By default
access to members of a C++ class is private. The private
members are not accessible outside the class; they can be
accessed only through methods of the class. The public
members form an interface to the class and are accessible
outside the class.

2.What is Data Abstraction?


Ans: Data abstraction refers to providing only essential
information to the outside world and hiding their background
details, i.e., to represent the needed information in program
without presenting the details.
3.List Out Concepts in C++.
Ans: There are some basic concepts that act as the building
blocks of OOPs.

 Classes & Objects


 Abstraction
 Encapsulation
 Inheritance
 Polymorphism

4.What is Object?
Ans: A Object is a Blueprint of a class, so basically an object is
created from a class. To use the data and access functions
defined in the class, we need to create objects.

Syntax:- ClassName ObjectVariableName;

5.What are the applications of OOPs.

Ans: Object-oriented programming (OOP) has many applications


in software development. Some of the main application areas
of OOP are:

 User interface design such as windows, menu


 Real Time Systems
 Simulation and Modeling
 Object-oriented databases
 AI and Expert System
 Neural Networks and parallel programming
 Decision support and office automation systems etc.

6.Diffrenciate Between Object Oriented and Procedural


Oriented programming

Ans:

Procedural Oriented Programming Object-Oriented Programming

In procedural programming, the program In object-oriented programming, the


is divided into small parts program is divided into small parts
called functions. called objects.

Procedural programming follows a top- Object-oriented programming follows


down approach. a bottom-up approach.

Object-oriented programming has


There is no access specifier in procedural
access specifiers like private, public,
programming.
protected, etc.
Procedural Oriented Programming Object-Oriented Programming

Adding new data and functions is not


Adding new data and function is easy.
easy.

Procedural programming does not have


Object-oriented programming provides
any proper way of hiding data so it is less
data hiding so it is more secure.
secure.

In procedural programming, overloading Overloading is possible in object-


is not possible. oriented programming.

In object-oriented programming, the


In procedural programming, there is no
concept of data hiding and inheritance
concept of data hiding and inheritance.
is used.

In procedural programming, the function In object-oriented programming, data is


is more important than the data. more important than function.

Procedural programming is based on Object-oriented programming is based


the unreal world. on the real world.

Object-oriented programming is used


Procedural programming is used for
for designing large and complex
designing medium-sized programs.
programs.

Procedural programming uses the concept Object-oriented programming uses the


of procedure abstraction. concept of data abstraction.

Code reusability absent in procedural Code reusability present in object-


programming, oriented programming.

Examples: C, FORTRAN, Pascal, Basic,


Examples: C++, Java, Python, C#, etc.
etc.

7.What is reference variable? What is its major use? in C++


Ans: A variable can be declared as a reference by putting ‘&’ in
the declaration. When a variable is declared as a reference, it
becomes an alternative name for an existing variable. &’ is
used for signifying the address of a variable or any memory.

Syntax: data_type &ref = variable;

8.What is inline function?


Ans: An inline Function is a function which is finished in only
one line. Means Function definition should be finished in only
one line.

9. What is the use of scope resolution operator.


Ans:1) To access variables when the local variables with the
same name.
2)To define a function outside a class.
3)To access Class’s Static variables.

10.What are Tokens in C++? Explain in detail.

Ans: A C++ program is composed of tokens which are the


smallest individual unit. Tokens can be one of several things,
including keywords, identifiers, constants, operators, or
punctuation marks.

There are 6 types of tokens in c++:

1. Keyword
2. Identifiers
3. Constants
4. Strings
5. Special symbols
6. Operators

11. How to create class and object?

Ans: A Class is defined with “class” keyword followed by the


name of the class.

Syntax for creating Object is Class_Name Object_Name;

12.What is Friend Function in C++?


Ans: A friend function of a class is defined outside that class'
scope but it has the right to access all private and protected
members of the class. Even though the prototypes for friend
functions appear in the class definition, friends are not member
functions.
A friend can be a function, function template, or member
function, or a class or class template, in which case the entire
class and all of its members are friends.
A friend function is defined using friend function.

13.Array of objects in C++?


Ans: When class is defined, only specification for objects is
defined. No memory is allocated. To use the data and to access
class we need to create objects.
The array of objects stores objects. The array of class type is
also known as array of objects.
Syntax: Class_Name Object_Name[No. of objects];
14. What is static data member? Explain its characteristics.

Ans: It is a variable which is declared with the static keyword,


it is also known as class member, thus only single copy of the
variable creates for all objects.

Any changes in the static data member through one member


function will reflect in all other object’s member functions.

Declaration

static data_type member_name;

15. Define Constructor and Destructor in C++


Ans: Constructor:-
A class constructor is a special member function of a class
that is executed whenever we create new objects of that
class.
Constructor gets call whenever the object created.
Constructor has no return type not even void.
Syntax:
Class_Name()
{
-----
//Constructure boby.
}
Destructor:-
A destructor will have exact same name as the class prefixed
with a tilde (~) and it can neither return a value nor can it
take any parameters. Destructor can be very useful for
releasing resources before coming out of the program like
closing files, releasing memories etc.

16. List the types of Constructor.


Ans:

17.What is default constructor?

Ans: Default constructors do not take any parameters. If a


default constructor is not provided by the programmer
explicitly, then the compiler provides a implicit default
constructor. In that case, the default values of the variables are
0.

Syntax:

Class_Name() {

………

……….

18. Write the rules for defining constructor.

Ans:

1) Constructure name should be same as Class name.


2)  Constructors are invoked automatically whenever the
object is created.
3) Constructors do not have return type.
4) Constructor can not be inherited, but from the derived
class we can call the base class constructors.
5) Constructor can not be virtual.
6) It is not possible to refers to the address of
constructors.
7) It is not possible to use the constructor as member of
union if the object is created with constructor.

18.What is inheritance? And its types.

Ans: In C++, it is possible to inherit attributes and methods from


one class to another. We group the "inheritance concept" into
two categories:

 derived class (child) - the class that inherits from another


class
 base class (parent) - the class being inherited from

To inherit from a class, use the : symbol.

 Itis useful for code reusability: reuse attributes and methods


of an existing class when you create a new class .

19.What is Abstract Class in C++.


Ans: Abstract classes are used to represent general concepts
(for example, Shape, Animal), which can be used as base
classes for concrete classes (for example, Circle, Dog).
No objects of an abstract class can be created (except for base
subobjects of a class derived from it) and no non-static data
members whose type is an abstract class can be declared.
Abstract types cannot be used as parameter types, as function
return types, or as the type of an explicit conversion (note this
is checked at the point of definition and function call, since at
the point of function declaration parameter and return type may
be incomplete).

20. What is Virtual Base class?

Ans: Virtual base classes are used in virtual inheritance in a


way of preventing multiple “instances” of a given class
appearing in an inheritance hierarchy when using multiple
inheritances.

21.Write the syntax of derived class constructor.

Ans: Syntax:

Derived_class_Name(Parameters)

//construction Defination;

22. Explain access specifies?

Ans: In C++, there are three access specifiers:

 public - members are accessible from outside the class


 private - members cannot be accessed (or viewed) from
outside the class
 protected - members cannot be accessed from outside
the class, however, they can be accessed in inherited
classes. You will learn more about Inheritance later.

23.What is polymorphism? Mention its types.


Ans:  we can define polymorphism as the ability of a message to be displayed in
more than one form. A real-life example of polymorphism is a person who at the
same time can have different characteristics. A man at the same time is a father, a
husband, and an employee. So the same person exhibits different behavior in
different situations. This is called polymorphism. Polymorphism is considered one
of the important features of Object-Oriented Programming.

Types of Polymorphism
 Compile-time Polymorphism
 Runtime Polymorphism

24.What is operator overloading?

Ans: 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 .

In C++, we can make operators work for user-defined classes. This


means C++ has the ability to provide the operators with a special
meaning for a data type, this ability is known as operator
overloading. For example, we can overload an operator ‘+’ in a class
like String so that we can concatenate two strings by just using +.
Other example classes where arithmetic operators may be overloaded
are Complex Numbers, Fractional Numbers, Big integers, etc.

25.List the types of operators that cannot be overloaded.


Ans: List of operators that cannot be overloaded
1) Scope Resolution Operator   (::)    
2) Ternary or Conditional Operator  (?:)   
3) Member Access or Dot operator  (.)    
4) Pointer-to-member Operator (.*)  
5) Object size Operator (sizeof) 
6) Object type Operator(typeid) 
7) static_cast (casting operator)
8) const_cast (casting operator)
9) reinterpret_cast (casting operator)
10) dynamic_cast (casting operator)

26.Write the rules for operator overloading


In C++, following are the general rules for operator overloading.
1) Only built-in operators can be overloaded. New operators can not
be created.
2) Arity of the operators  cannot be changed.
3) Precedence and associativity of the operators cannot be changed.
4) Overloaded operators cannot have default arguments except the
function call operator () which can have default arguments.
5) Operators cannot be overloaded for built in types only. At least
one operand must be used defined type.
6) Assignment (=), subscript ([]), function call (“()”), and member
selection (->) operators must be defined as member functions
7) Except the operators specified in point 6, all other operators can
be either member functions or a non member functions.
8 ) Some operators like (assignment)=, (address)& and comma (,) are
by default overloaded.

You might also like