[转] Explain Java Encapsulation & Polymorphism & Inheritance

  • 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)


  • 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.
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值