Social Icons

Friday, January 11, 2013

C++ INTERVIEW QUESTIONS FOR FRESHERS WITH ANSWERS


1. What is a class?
Ans: The objects with the same data structure (attributes) and behavior (operations) are called class.


2. What is an object?
Ans: It is an entity which may correspond to real-world entities such as students, employees, bank account. It may be concrete such as file system or conceptual such as scheduling policies in multiprocessor operating system.
Every object will have data structures called attributes and behavior called operations.


3. What is the difference between an object and a class?
Ans: All objects possessing similar properties are grouped into class.
Example :–person is a class, ram, hari are objects of person class. All have similar attributes like name, age, sex and similar operations like speak, walk.

Class person
{
private:
char name[20];
int age;
char sex;
public: speak();
walk();
};


4. What is the difference between class and structure?
Ans: In class the data members by default are private but in structure they are by default public


5. Define object based programming language?
Ans: Object based programming language support encapsulation and object identity without supporting some important features of OOPs language.
Object based language=Encapsulation + object Identity


6. Define object oriented language?
Ans: Object-oriented language incorporates all the features of object based programming languages along with inheritance and polymorphism.

Example: – c++, java.

7. Define OOPs?
Ans: OOP is a method of implementation in which programs are organized as co-operative collection of objects, each of which represents an instance of some class and whose classes are all member of a hierarchy of classes united through the property of inheritance.


8. What is public, protected, and private?
Ans: These are access specifier or a visibility lebels .The class member that has been declared as private can be accessed only from within the class. Public members can be accessed from outside the class also. Within the class or from the object of a class protected access limit is same as that of private but it plays a prominent role in case of inheritance


9. What is a scope resolution operator?
Ans: The scope resolution operator permits a program to reference an identifier in the global scope that has been hidden by another identifier with the same name in the local scope.


10. What do you mean by inheritance?
Ans: The mechanism of deriving a new class (derived) from an old class (base class) is called inheritance. It allows the extension and reuse of existing code without having to rewrite the code from scratch.


11. What is abstraction?
Ans: The technique of creating user-defined data types, having the properties of built-in data types and a set of permitted operators that are well suited to the application to be programmed is known as data abstraction. Class is a construct for abstract data types (ADT).


12. What is encapsulation?
Ans: It is the mechanism that wraps the data and function it manipulates into single unit and keeps it safe from external interference.


13. How variable declaration in c++ differs that in c?
Ans: C requires all the variables to be declared at the beginning of a scope but in c++ we can declare variables anywhere in the scope. This makes the programmer easier to understand because the variables are declared in the context of their use.


14. What are the c++ tokens?
Ans: c++ has the following tokens
I. keywords
II. Identifiers
III. Constants
IV. Strings
V. operators


15. What do you mean by reference variable in c++?
Ans: A reference variable provides an alias to a previously defined variable.
Data type & reference-name = variable name

prepending variable with "&" symbol makes it as reference.
for example:
int a;
int &b = a;
 

16. What do you mean by implicit conversion?
Ans: Whenever data types are mixed in an expression then c++ performs the conversion automatically.
Here smaller type is converted to wider type.
Example- in case of integer and float integer is converted into float type.


17. What is the difference between method overloading and method overriding?
Ans: Overloading a method (or function) in C++ is the ability for functions of the same name to be defined as long as these methods have different signatures (different set of parameters). Method overriding is the ability of the inherited class rewriting the virtual method of the base class.


18. What are the defining traits of an object-oriented language?
The defining traits of an object-oriented language are:
encapsulation
inheritance
polymorphism

Ans:
Polymorphism: is a feature of OOPL that at run time depending upon the type of object the appropriate method is called.

Inheritance: is a feature of OOPL that represents the “is a” relationship between different objects (classes). Say in real life a manager is a employee. So in OOPL manger class is inherited from the employee class.
Encapsulation: is a feature of OOPL that is used to hide the information.

19. What is polymorphism?
Ans: Polymorphism is the idea that a base class can be inherited by several classes. A base class pointer can point to its child class and a base class array can store different child class objects.