View Feed
group-icon
Java Developers
Community of Java Developers: Get Java Programming Help from fellow Java Developers across the world.
655 Members
Join this group to post and comment.

Why abstract class used in java ?

hay friends

as we know that we can not create the instance of abstract class than why we use abstract class....
Anoop Kumar
Anoop Kumar • Jun 6, 2013
suppose you have to write code for TwoWheeler.
Lets make a abstract class for TwoWheeler do following things in common
1. Turning mechanism
2. break mechanism
But following things can be differ from kind of TwoWheeler
A. Gear Mechanism

you can write with implementation of 1 & 2 method in abstract class and provide a abstract method for GearMechanism.
Now whatever class will extend TwoWheeler class, they already have method 1,2 and just need to implement method A. this give you proper reuse of code.

PS: In java, always think as if in real scenarios, makes java like a cake. more you eat more you get amused😀
ianoop
suppose you have to write code for TwoWheeler.
Lets make a abstract class for TwoWheeler do following things in common
1. Turning mechanism
2. break mechanism
But following things can be differ from kind of TwoWheeler
A. Gear Mechanism

you can write with implementation of 1 & 2 method in abstract class and provide a abstract method for GearMechanism.
Now whatever class will extend TwoWheeler class, they already have method 1,2 and just need to implement method A. this give you proper reuse of code.

PS: In java, always think as if in real scenarios, makes java like a cake. more you eat more you get amused😀

Thank you anoop

you have explain in very nice way and any one can easily understand...

Share this content on your social channels -