(103 Pepar) Priyesh Padiya

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

B.C.

A SEM-3
October/November-2016
C++ & Object Oriented Program
One mark[I.M.P Questions] (1M)

1) What are the c++ stream classes ?


Ans. Stream classes in c++ are used to input and
output oprations on files and io(input output)
devices.

2) What are the modes of files used in file program ?


Ans. In c++ we have a set of file handling methods.
These include ifstream, ofstream and fstream.
3) What will be output of following program ?
#include <iostream.h>
int main()
{
int a;
a=5+3 * 5;
cout << a;
return 0;
}
Ans.20
4) Explain static member function.
Ans. A static member function can access only the
names of static members, enumerators, and
nested types of the class in which it is declared.

5) What is copy constructor ?


Ans. A copy constructor is a member function that
initializes an object using another object of the
same class.

6) Discuss any three features of object oriented


programming.
Ans.
 Classes.

 Encapsulation.

 Abstraction.

 Inheritance.

 Polymorphism.

7) Which metod is used to convert basic to class type


Conversation ?
Ans. For Example, the operator double() converts
a class object to type double, the operator int()
converts a class type object to type int, and so on.

8) Explain inline function.


Ans. Inline function is a function that is expanded
in line when it is called.

9) What will be output of following code ?

#include <iostream.h>
class Base
{
public:
virtual void show()
{
Cout<<”In Base \n”;
}
};
class Derived : public Base
{
public:
void show()
{
cout<<”Inderived \n”;
}
};
int main()
{
Base * b =new Derived;
b-> show (); // RUN-TIME POLYMORPHISM
return 0;
}
Ans. Inderived

10) How protected keyword is useful ?


Ans. The protected keyword specifies access to
class members in the member-list up to the next
access specifier ( public or private ) or the end of
the class definition.

11) What is destructor ? How many destructors


can be declared in programming?
Ans. Destructor is also a special member function
like constructor. Destructor destroys the class
objects created by constructor. Destructor has the
same name as their class name preceded by a tilde
(~) symbol. It is not possible to define more than
one destructor.

12) How can we access private member function


of the class ?
Ans. We can access private method in other
class using the virtual function, A virtual function
is a member function which is declared within a
base class and is re-defined (Overridden) by a
derived class.

13) How overloading of template function


occues?
Ans. The name of the function templates are the
same but called with different arguments is known
as function template overloading.

14) Is it possible to declare constructor as a virtual


function ? Explain with reason .
Ans. In C++, the constructor cannot be virtual,
because when a constructor of a class is executed
there is no virtual table in the memory, means no
virtual pointer defined yet. So, the constructor
should always be non-virtual. But virtual destructor
is possible.

15) What is hybrid inheritance ?


Ans. The process of combining more than one type
of Inheritance together while deriving subclasses in
a program is called a Hybrid Inheritance.
16) Explain any three differences between C and
C++.
Ans. In a nutshell, the main difference between C
and C++ is that C is a procedural with no support for
objects and classes, whereas C++ is a combination
of procedural and object-oriented programming
languages.

17) What are C++ tokens ? List out them.


Ans. A token is the smallest element of a C++
program that is meaningful to the compiler. The C++
parser recognizes these kinds of tokens: identifiers,
keywords, literals, operators, punctuators, and
other separators.

18) What is difference between object and class ?


Ans. Object is an instance of a class. Class is a
blueprint or template from which objects are
created. Object is a real world entity such as pen,
laptop, mobile, bed, keyboard, mouse, chair etc.
Class is a group of similar objects.

19) Give an example of polymorphism.


Ans. #include <iostream>

using namespace std;


class Addition {
public:
int ADD(int X,int Y) // Function with parameter
{
return X+Y; // this function is performing addition of two
Integer value
}
int ADD() { // Function with same name but without
parameter
string a= "HELLO";
string b="SAM"; // in this function concatenation is
performed
string c= a+b;
cout<<c<<endl;

}
};
int main(void) {
Addition obj; // Object is created
cout<<obj.ADD(128, 15)<<endl; //first method is called
obj.ADD(); // second method is called
return 0;
}
Output: 143

20) How to inherit a base class to child class ?


Explain with syntax.
Ans. Parent class is known as base class while child
class is known as derived class. The derived class can
inherit data members, member functions of base
class.
syntax: class base { ... };
class derived : base { ... };

You might also like