What are Encapsulation, Polymorphism and Inheritance?

Answers were Sorted based on User's Feedback



What are Encapsulation, Polymorphism and Inheritance?..

Answer / janet

Encapsulation is the mechanism that binds together
code and data it manipulates and keeps both safe from
outside interface and misuse.
Inheritence is the process by which one object
acquires the properties of another object.
polymorphism is the feature that allows one
interface to be used for general class actions.

Is This Answer Correct ?    53 Yes 7 No

What are Encapsulation, Polymorphism and Inheritance?..

Answer / sivadasan

I. Encapsulation - Hiding the implementation details of a
Class. Once a class is Encapsulated then we Cannot directly
access that class members. We can achieve encapsulation
like the following,

Eg: public class <class Name> {
private <member_1>;
private <member_2>;
}

In the above example members of the public class declared
as private. So any other class members cannot directly
access the members of that class, and those are stored as a
Single Unit. That is Encapsilation.

Real Time Example - Medical Capsule (Different medicines
packed as in single Capsule)


II. Polymorphism - Ability to process an Object differently
depending upon thier Data Type or Class.

In simple words, One function - different implementations.

There two types of Polymorphism :

1) Compile time Polymorphism - The compiler know that the
way of execution of the program , means - which method
have to be invoked at compilation time. It is achieved by

Method Overloading - Same method name, may be different
parameters, may be different data type, may be different
return type. Method Overloading perform only inside of the
class.

2) Run-Time Polymorphism - The compiler doesn't know the
way of execution of the program. It will take the decision
for execute the program at Run-Time. It is achieved by

Method Overriding - Same Method name, same signatures,
similar DataType, Return type also should be the same.
Method Overriding perform at Subclass.

Real time Example - A man perform multiple role.
He is Employee of his office,He is father of his Childrens,
He is Husband of his wife, He is Son of his Parents.

Inheritance - A class of object can inherit the properties
and methods of an another class of object. Advantage :
reusabilty of code and accessibilty of properties and
methods of derived class by subclass.

Real Time example - Father - Son Relationship.


I hope you will get idea about all those things.

If any issue let me know imm'tly.

Regards,

S.Sivadasan
Coromandel Infotech India Ltd.,
sivadasan.s@c2il.com

Chennai.

Is This Answer Correct ?    46 Yes 3 No

What are Encapsulation, Polymorphism and Inheritance?..

Answer / karthickeyan s

Encapsulation is nothing but,that binds together the code
and data, and it manipuletes and keep it away from external
interface an misuse.


Polymorphism is that allows one interface to be used for
general class actions.

Is This Answer Correct ?    13 Yes 5 No

What are Encapsulation, Polymorphism and Inheritance?..

Answer / mohankumar

Encapsulation is also known as information hiding,it is to
protect data from the client using the classes but still
allowing the client to access the data,but do not modifying it.

Polymorphism ability to perform differently on different forms.

Inheritance means one base class derived from one or more
classes.

Is This Answer Correct ?    8 Yes 2 No

What are Encapsulation, Polymorphism and Inheritance?..

Answer / sakthi k

Wrapping of data and functions together is known as
Encapsulation. Eg: Capsule.


Ability of an object to take more than one form is known as
polymorphism.
Two types of polymorphism are availabe
Compile time
Run time

The process of acquiring the base class property is known
as Inheritance

Is This Answer Correct ?    3 Yes 1 No

Post New Answer

More Core Java Interview Questions

What is the purpose of default constructor?

0 Answers  


what is the difference between String and StringBuffer classes?

2 Answers   Infosys,


Which collection does not allow duplicates in java?

0 Answers  


What is difference between module and function?

0 Answers  


How many bits is a double?

0 Answers  






Read data from console and print in one file. That would be in C:\temp ? Thanks, Bose

3 Answers   Oracle, Surya Software,


Class c implements interface I containing method m1 and m2 declarations. Class c has provided implementation for method m2. Can I create an object of class c?

0 Answers  


Is java code slower than native code?

0 Answers  


How do I start learning java?

0 Answers  


program to find 25 square = 625 here the 625 of last two digits is equal to 25, i don't know excatly what this type of number is called

1 Answers   Huawei,


What is the use of hashmap in java?

0 Answers  


how to get the max salary and name of employee from arraylist without using the Comperator or even Comparable interface?

2 Answers  


Categories