what abstraction,encapsulation,inheritance? Define with example.

what abstraction,encapsulation,inheritance? Define with example.

Abstraction:-Abstraction is the process of hiding the details and  exposing only the essential features of a particular concept or object.  
Abstraction is another good feature of OOPS. Abstraction means to show only the necessary details to the client of the object
Example:-A simple example is using a base class "Animal", with a virtual function "Walk". In the case two-legged versus four-legged animals, both of them walk, but the actual mechanics are different. The "Walk" method abstracts the actual mechanics behind the walking that each "Animal" does.
2nd example:-A class called Animal.
It has properties like ears,colour, eyes but they are not defined.
It has methods like Running(), Eating(), etc. but the method does not have any body, just the definition.

Encapsulation:-Encapsulation is the term given to the process of hiding all the details of an object that do not contribute to its essential characteristics.its wrapping of data and members in a single unit.Encapsulation is a process of hiding all the internal details of an object from the outside world .
1:- Encapsulation is the ability to hide its data and methods from outside the world and only expose data and methods that are required .
2.Encapsulation gives us maintainability, flexibility and extensibility to our code. 
3.Encapsulation provides a way to protect data from accidental corruption .
4.Encapsulation gives you the ability to validate the values before the object user change or obtain the value .
5.Encapsulation allows us to create a "black box" and protects an objects internal state from corruption by its clients.
6.Encapsulation is the technique or process of making the fields in a class private and providing access to the fields using public methods.

Example:-cars and owners...
all the functions of cars are encapsulated with the owners..
No one else can access it...
Inheritance:-In object-oriented programming (OOP), Inheritance is a way to compartmentalize and reuse code by creating collections of attributes and behaviors called objects which can be based on previously created objects. In classical inheritance where objects are defined by classes.
classes can inherit other classes. The new classes, known as Sub-classes (or derived classes), inherit attributes and behavior of the pre-existing classes, which are referred to as Super-classes.
the process of deriving one class from parent class called .

Seccond Example:-
Kingfisher jet
Flying Things

Date:2013-10-10 00:00:00

Post Your Answers

User Email:

User Name:

Related C Links

C interview questions and answers for experienced and fresher