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

Replies

  • Anoop Kumar
    Anoop Kumar
    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😀
  • hare singh nayak
    hare singh nayak
    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...

You are reading an archived discussion.

Related Posts

please see the attach image :
AMD has decided to give up the long-running Windows exclusivity stand and extend its loyalty to Google's Android and Chrome OS Operating Systems. Advanced Micro Devices is now open to...
After gathering more than 100 million users around the world to opt for the 'One Channel' during its open beta phase, the new channel design goes universal today. If you...
If you care for energy, Microsoft has something very important message for you - 'Ditch Chrome & Firefox and switch over to IE10'. Why? Because Microsoft's latest study finds out...
Stanford University scientists writing in Nature Communications asserts that novel electrodes made of silicon and conducting polymer hydrogel betters the performance of rechargeable Lithium-ion batteries. Using this method, these scientists...