What are Encapsulation, Polymorphism and Inheritance?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What happens if we override only equals?

582


Can we catch more than one exception in a single catch block?

628


Why bytecode is called bytecode?

588


What is wrapper class example?

538


What is the difference between call by reference and call by pointer?

501






What is ph and buffers?

520


What is a superclass?

926


Can an anonymous class be declared as implementing an interface and extending a class in java programming?

646


If an object reference is set to null, will the garbage collector immediately free the memory held by that object?

635


what is difference between equals and ==?

590


Is 0 true or is 1 true?

516


What is member in java?

494


What are the two categories of data types in the java programming language?

507


Explain about anonymous inner classes ?

580


Can singleton class be serialized?

516