Wednesday, June 11, 2008

OOPS Interview Questions

Interview Questions : OOPS

1. What is OOPs?

OOPs - Object Oriented Programming Languages & Systems
Everything in the world is an object. The type of the object may vary. In OOPS, we get the power to create objects of our own, as & when required. OOPs is a programming methodology where each entity is an object.
It is a method of computer programming where entities of related data together with routines associated with it are treated as one object in the program.

2. What are the basic concepts of OOPs?

The following are the basic concepts of OOPs:
Classes, Objects, Data abstraction and encapsulation, Polymorphism, Inheritance, Message Passing, and Dynamic Binding.

3. What is a class?
Class is an entity which consists of member data and member functions which operate on the member data bound together.

4. What is an object?
Objects are instances of classes. Class is a collection of similar kind of objects. When a class is created it doesn’t occupy any memory, but when instances of class is created i.e., when objects are created they occupy memory space.

5. What is data encapsulation?
Wrapping up of member data and member functions together in a class is called data encapsulation.

6. What is data abstraction?
Data abstraction refers to the act of providing only required features and hiding all the non-essential details for usage.

7. What are ADTs?
ADTs stand for abstract data types. Classes which provide data abstraction are referred to as ADTs.

8. What is inheritance?
The process of inheriting the properties of one object by another object is called inheritance.

9. What is polymorphism?
The feature of exhibiting many forms is called polymorphism.

10. What are the steps involved in message passing?
The following are the steps involved in message passing:
Creating classes, creating objects, and creating communication between objects.

11. What is dynamic binding?
The feature that the associated code of a given function is not known till run time is called dynamic binding.

12. What are the advantages of OOP?
Data hiding helps create secure programs.
Redundant code can be avoided by using inheritance.
Multiple instances of objects can be created.
Work can be divided easily based on objects.
Inheritance helps to save time and cost.
Easy upgrading of systems is possible using object oriented systems.

13. Give an example for object based programming language.
Ada is an example for object based programming language.

14. Write the features of object based programming language.
Data hiding, data encapsulation, operator overloading and automatic initialization and clear up of objects are the important features exhibited by object based programming languages.

15. What is the difference between structure in C and class in C++?
In C structure, by default the members are public. Whereas in C++ class, by default the members are private.

16. What are the sections in class specification?
There are basically two sections in class specification: Class declaration and class function definition.

17. Write the syntax for class declaration.
Syntax:
class
{
private:
variables;
functions;
public:
variables;
functions;
};

18. What are class members?
The variables and functions used in a class are called class members.

19. What are the visibility labels?
Private, public and protected are the visibility labels.

20. Give an example for class declaration.
Ex.:
class area
{
int r;
public:
void get(int r);
void area(int r);
};

21. How does a class provide data hiding?
Data hiding is provided by a class by the use of visibility label private which allows only the member functions to access the data declared as private.

22. What are the ways of defining member functions?
Member functions can be defined in two ways, one inside the class definition and the other outside the class definition.

23. Write the syntax for defining member functions inside the class.
Syntax:
class
{
private:
variables;
public:
variables:
return type
{
statements;
}
};
24. Write the syntax for defining member functions outside the class.
Syntax:
return type :: (arguments)
{
body;
}

25. What does member functions represent?
Member functions of a class represent the behaviour of a class.

26. Write the syntax for making an outside function inline?
Member functions can be made inline even though we define them outside the class by using the keyword inline.
Syntax:
class
{
variables;
public:
return type (arguments);
};
inline return type :: (arguments)
{
body;
}

27. What is an object?
A region of storage with associated semantics is called an object.

28. What is the difference between abstract and interface.
Abstract can,t support multiple inheritence.
Interface can suppport the multiple inheritence.

Abstract have accesbulity modifiers.
Interface have no accesbulity modifiers.

29. What is Namespace.
A namespace is an abstract container or environment created
to hold a logical grouping of unique identifiers (i.e.,
names).
Namespaces allow to group entities like classes, objects
and functions under a name.

30. What is difference between class and object.
Class : class ia a blueprint or prototype from which object
are created
Object: Object is a Software bundles of related state and
behavior.