Friday, 14 September 2012

C++ Interview Questions-1


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

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:
1.Encapsulation
2.Inheritance
3.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.

20. What do you mean by inline function?
Ans: An inline function is a function that is expanded inline when invoked.i.e., the compiler replaces the function call with the corresponding function code. An inline function is a function that is expanded in line when it is invoked. That is the compiler replaces the function call with the corresponding function code (similar to macro).

No comments:

Post a Comment