CrazyEngineers
  • Why abstract class used in java ?

    Updated: Oct 26, 2024
    Views: 1.5K
    hay friends

    as we know that we can not create the instance of abstract class than why we use abstract class....
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Anoop Kumar

    MemberJun 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😀
    Are you sure? This action cannot be undone.
    Cancel
  • hare singh nayak

    MemberJun 6, 2013

    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...
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register