Professional Documents
Culture Documents
2 MARK QUESTIONS
UNIT - I
1. DEFINE ENCAPSULATION.
Encapsulation is the process of combining data and functions into a single unit
called class. Using the method of encapsulation, the programmer cannot directly access the data.
Data is only accessible through the functions present inside the class.
2. WHAT IS FUNCTION OVERLOADING
A function with the same name performing different operations is called function
overloading. To achieve function overloading, functions should be declared with the same name
but different number and type of arguments.
3. WHAT IS OPERATOR OVERLOADING? GIVE EXAMPLES.
The same operator performing different operations is called operator overloading.
E.g. two matrices cannot be directly overloaded. But the + operator can be overloaded to perform
Addition of two matrices or other user defined data types.
4. DEFINE A CLASS.
Class is a collection of data members with its member functions. Classes are data
types based on which objects are created. Objects with similar properties and methods are
grouped together to form a Class.
5. WHAT IS AN OBJECT?
An object is an instance of a class. Any real world entity such as pen, book,
bird, student etc., can be termed as an object. They may also represent user-defined data. They
contain both data and code.
6. WHAT ARE THE DIFFERENCES BETWEEN STRUCTURAL AND OBJECT ORIENTED
PROGRAMMING?
STRUCTURAL PROGRAMMING:
1. Importance is given to functions.
2. Reusability of code is not possible.
3. Does not provide abstraction.
previously defined variable. A reference is, exactly as the name suggests, a reference or pointer to
another object.
Its syntax is given by,
data-type & reference-name = variable-name;
Eg : int &ptr = rupee;
1. DEFINE CONSTRUCTOR.
A constructor is a special member function whose task is to initialize the objects
of its class. It has the same name as the class. It gets invoked whenever an object is created to
that class.
Eg: class sample
{
Public:
Sample ();
}
2. LIST SOME OF THE SPECIAL CHARACTERISTICS OF CONSTRUCTOR.
Constructors should be declared in the public section.
They are invoked automatically when the objects are created.
They do not have return types
They cannot be inherited.
3. GIVE THE VARIOUS TYPES OF CONSTRUCTORS.
There are four types of constructors. They are,
Default constructors A constructor that accepts no parameters.
Parameterized constructors The constructors that can take arguments.
Copy constructor It takes a reference to an object of the same class as
itself as an argument.
//destructor declaration
};
File::~File()
{
close();
// destructor definition
}
7. LIST SOME OF THE RULES FOR OPERATOR OVERLOADING.
Only existing operators can be overloaded.
We cannot change the basic meaning of an operator.
The overloaded operator must have at least one operand.
Overloaded operators follow the syntax rules of the original operators.
public: string( )
{
name = new char[length +1];
}
18. WRITE AT LEAST FOUR RULES FOR OPERATOR OVERLOADING.
* Only the existing operators can be overloaded.
* The overloaded operator must have at least one operand that is of user defined
data type.
* The basic meaning of the operator should not be changed.
* Overloaded operators follow the syntax rules of the original operators. They
cannot be overridden.
19. DEFINE BINARY OPERATOR OVERLOADING.
Binary operator overloading performs its operation by using 2 objects. The first
object is passed as an implicit operand and the second object is passed explicitly.
20. DEFINE EXPLICIT CONSTRUCTOR.
Constructor can be defined explicitly by using the keyword explicit is known
as an explicit constructor. The explicit constructor will be executed when we call the constructor
explicitly.
Ex:
explicit brother (string name)
{
Body of the explicit constructor
}
Note: brother is a class name.
21. HOW WILL YOU OVERLOAD UNARY AND BINARY OPERATOR USING FRIEND
FUNCTION?
When unary operators are overloaded using friend function, it takes one reference
argument (object of the relevant class). When binary operators are overloaded using friend
function, it takes two explicit arguments.
UNIT III
1. DEFINE TEMPLATE.
A template in C++ allows the construction of a family of template functions and
classes to perform the same operation on different data types. The template type arguments
are called generic data types.
2. DEFINE FUNCTION TEMPLATE.
The templates declared for functions are called function templates. A function
template is prefixed with a keyword template and list of template type arguments.
3. WHAT IS THE SYNTAX USED FOR WRITING FUNCTION TEMPLATE?
template
<class T>,.>
The templates declared for classes are called class templates. Classes can also be
declared to operate on different data types. A class template specifies how individual
classes can be constructed similar to normal class specification.
UNIT- IV
1. DEFINE INHERITANCE.
Inheritance is the most important property of object oriented
programming. It is a mechanism of creating a new class from an already defined
class. The old class is referred to as base class. And the new one is called derived
class.
2. WHAT ARE THE ADVANTAGES OF AN INHERITANCE?
* Inheritance is used for extending the functionality of an existing class.
* By using this, we have multiple classes with some attributes common
to them.
};
* It acts like an empty bucket that the derived class is supposed to fill.
A class can contain objects of other classes as its members. This kind of
relationship is called object composition or containership or nesting or has a relationship.
Polymorphism means the ability to take more than one form. That means
it performs more than one operation by using a single operator. Polymorphism is
implemented using the overloaded functions and operators.
Run Time Type Information (RTTI) is a very powerful tool in C++ for
finding out the type of an object at run time. RTTI also impacts the performance of the
system. Most of the compilers provide RTTI, but disable it by default.