Sie sind auf Seite 1von 7

EXPECTED VIVA QUESTIONS

1. What is a class?

Class is concrete representation of an entity. It represents a group of objects, which hold similar attributes and
behavior. It provides Abstraction and Encapsulations. Classes are generally declared using the keyword class.

2. What is an Object? What is Object Oriented Programming?

Object represents/resembles a Physical/real entity. An object is simply something you can give a name.

Object Oriented Programming is a Style of programming that represents a program as a system of

objects and enables code-reuse. Object is a software bundle of variables and related methods.

Objects have state and behavior. object is a real life entity which contains data and functions
to operate on that data.
3. What is Encapsulation?

Encapsulation is binding of attributes and behaviors. Hiding the actual implementation and exposing the

functionality of any object. Encapsulation is the first step towards OOPS, is the procedure of covering up

of data and functions into a single unit (called class). Its main aim is to protect the data from out side

world

4. What is Abstraction?

Hiding the complexity. It is a process of defining communication interface for the functionality and

hiding rest of the things.

5. What is Overloading?

Adding a new method with the same name in same/derived class but with different number/types of

parameters. It implements Polymorphism.

6. What is Inheritance?

It is a process in which properties of object of one class acquire the properties of object of another

class.

7. What is an Abstract class?

An abstract class is a special kind of class that cannot be instantiated. It normally contains one or more

abstract methods or abstract properties. It provides body to a class.

8. What is Polymorphism? And its type?

Poly" means "many" and "morph" means "form". Polymorphism is the ability of an object (or
reference) to assume (be replaced by) or become many different forms of object.
Example: function overloading, function overriding, virtual functions. Another example can
be a plus? +? sign, used for adding two integers or for using it to concatenate two strings
There are two types of polymorphism-
1)Run time polymorphism –Address of the function determine at the runtime is
known as runtime polymorphism
2) Compile time polymorphism- Address of the function determine at the compile
time is known as runtime polymorphism
9. What do you mean by iostream.h?

10 What is inheritance and its type?

11 What is the difference between c and c++?


12. What are the differences between a class and an object?
Ans: Object is an instance of a class. The class is a blueprint of all the objects which
Share common properties and the behavior. Class represents the abstract data type and
Object is a real-world entity.
12 What are the differences between a structure and a class?
Ans: There is no difference in structure and a class except that class members are private
by default and structure members are public by default.
13 What is the difference b/n public, private and protected?

1. Public: The data members and methods having public as access outside the class.

2. Protected: The data members and methods declared as protected will be accessible to the class methods
and the derived class methods only.

3. Private: These data members and methods will be accessible not from objects created outside the class.

14 What is the difference b/n variable declaration and definition?


Definition

Ex - int a=5
Tell the
compiler
about the
variable: its
type and
name, as
well as
allocated a
memory
cell for
the variable

Declaration

Ex- int a
Describe
information
``about'' the
variable,
variable,
doesn’t
allocate
memory
cell for the
variable

15 What is a void return type?

A void return type indicates that a method does not return a value.

16What is the difference between a while statement and a do statement?


A while loop is a entry control loop .A do while loop is a exit control loop, in this loop at least
one time a condition is executed always and it also terminated with semicolon.
What is a nested class? Why can it be useful?

A nested class is a class enclosed within the scope of another class. For example: // Example
1: Nested class // class Outer Class {class Nested Class {// …}; //...

17What is inline function?


Normally, a function call transfers the control from the calling program to the function and after
the execution of the program returns the control back to the calling program after the function call.
These concepts of function saved program space and memory space are used because the function
is stored only in one place and is only executed when it is called. This concept of function execution
may be time consuming since the registers and other processes must be saved before the function
gets called. The extra time needed and the process of saving is valid for larger functions. If the
function is short, the programmer may wish to place the code of the function in the calling program
in order for it to be executed. This type of function is best handled by the inline function. In this
situation, the programmer may be wondering “why not write the short code repeatedly inside the
program wherever needed instead of going for inline function?” Although this could accomplish the
task, the problem lies in the loss of clarity of the program. If the programmer repeats the same code
many times, there will be a loss of clarity in the program. The alternative approach is to allow inline
functions to achieve the same purpose, with the concept of functions.
18 What is the difference between overloading and overriding?

Overloading - Two functions having same name and return


Type, but with different type and/or number of arguments.
Overriding - When a function of base class is re-defined in
the derived class.

19 What is array and its type?


20 What is the difference b/n array and pointer?
Pointer –pointer is a variables that hold the address of another variable .It is used to manipulate
data using the address, pointer use the * operator to access the data pointed by them.
Array –array use subscripted [] variable to access and manipulate the data ,array variables can be
equivalently written using pointer expression.

Tokens - The smallest individual units in a program are known as tokens, c++ has the following tokens:
Example of tokens: - }, {, “ “, int

 Keywords
 Identifiers
 Constants

Identifier:
In our everyday, we give names to different things so they can be
Referred easily. Similarly, in C+, we use identifiers to name user created entities
Which may be?
• Variable
• Function

• Type e.g. a class

21 What is default Constructor?

Constructor with no arguments or all the arguments has default values. In Above Question Test() is a

default constructor

22 What is friend function?

As the name suggests, the function acts as a friend to a class. As a friend of a class, it can access its

private and protected members. A friend function is not a member of the class. But it must be listed in

the class definition.

23 What is a scope resolution operator?

A scope resolution operator (::), can be used to define the member functions of a class outside the

class.

24 What do you mean by pure virtual functions?

A pure virtual member function is a member function that the base class forces derived classes to

provide. Normally these member functions have no implementation. Pure virtual functions are equated

to zero. class Shape

public: virtual void draw() = 0;

};

25 What are the advantages of inheritance?

It permits code reusability. Reusability saves time in program development. It encourages the reuse of

proven and debugged high-quality software, thus reducing problem after a system becomes functional

26 What are virtual functions? Describe a circumstance in which virtual functions would be appropriate

Virtual functions are functions with the same function prototype that are defined throughout a class

hierarchy. At least the base class occurrence of the function is preceded by the keyword virtual. Virtual

functions are used to enable generic processing of an entire class hierarchy of objects through a base

class pointer. For example, in a shape hierarchy, all shapes can be drawn. If all shapes are derived from

a base class Shape which contains a virtual draw function, then generic processing of the hierarchy can

be performed by calling every shape’s draw generically through a base class Shape pointer.
27 Distinguish between virtual functions and pure virtual functions

A virtual function must have a definition in the class in which it is declared. A pure virtual function does

not provide a definition. Classes derived directly from the abstract class must provide definitions for the

inherited pure virtual functions in order to avoid becoming an abstract base class

28 What is the difference between parameter and arguments?

Parameter –While defining method, variable passed in the method are called parameters.

Arguments-While using those methods value passed to those variables are called arguments.

29 What are the different types of parameters?


There are two types of parameters associated with functions. they are:
(a) Actual parameter: The parameters associated with function call are called
actual parameters.
(b) Formal parameter: The parameters associated with the function definition
are called formal parameters.
30 Keywords:

Keywords are predefined reserved identifiers that have special meanings. They cannot be used as
identifiers in your program. Keyword is a word that the compiler already knows, i.e. when the compiler
sees a keyword somewhere in the program it knows what to do automatically.
For example, when the compiler encounters the keyword ‘int’, it knows that ‘int’ stands for an
integer. Or if the compiler reads a ‘break’, then it knows that it should break out of the current
loop.

31 What are the common Data types?and its range?

keyword Range (low) (high) Bytes of memory(size)


Char -128 127 1
int -32768 32767 2
long -2147483648 2147483647 4
float 3.4 x 10-38 3.4 x 1038 4
double 1.7 x 10-308 1.7 x 10308 8
30 what is the Syntax of for loop?

for (initillization; condition;increment)

32.Explain the different types of parameter passing.


types of parameter passing in C++. They are:
(a) Call by value: In this method, the actual parameters are copied into the
Formal parameters and the change in the formal parameters do not affect the
actual parameter. In this passing only the value so that copy of the value is sent
to function, original value will not change.
(b) Call by reference: In this mode of parameter passing instead of passing the
Value to a function, a reference or an alias to the actual parameter is passed. The
changes made in the formal parameters are reflected in the actual parameters. In
this ,address of the value is passed ,so the original value will be change .
33 what is the use of getch() function in a program.difference b/w getch() and
getche()?
getch() returns to the program after hitting any
key.
getche() waits for the character, read it and
then returns
to the program

Das könnte Ihnen auch gefallen