Abstract class and its real time usage
need real time application usage where we use abstract class and its needs
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Aakash MauryaRank #114 · 19.8K reputationPosted Aug 12, 2019, 4:29 AM EDT
Vishal PatelRank #3,290 · 437 reputationPosted Aug 12, 2019, 8:00 AM EDT
Sonu GuptaRank #1,261 · 1.4K reputationPosted Aug 12, 2019, 7:28 PM EDT
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Aug 12, 2019, 7:43 PM EDT
Jayanth ReddyRank #8,652 · 218 reputationPosted Aug 20, 2019, 8:59 PM EDT
Mageshwaran RRank #411 · 6.1K reputationPosted Nov 25, 2019, 5:23 AM EST
Samir BhogaytaRank #1,266 · 1.4K reputationPosted Dec 2, 2019, 10:52 PM EST
Ajay GohilRank #2,370 · 599 reputationPosted Dec 9, 2019, 5:30 PM EST
Why we need an abstract class?
Lets say we have a class
Animalthat has a methodsound()and the subclasses of it likeDog,Lion,Horse,Catetc. Since the animal sound differs from one animal to another, there is no point to implement this method in parent class. This is because every child class must override this method to give its own implementation details, likeLionclass will say “Roar” in this method andDogclass will say “Woof”.So when we know that all the animal child classes will and should override this method, then there is no point to implement this method in parent class. Thus, making this method abstract would be the good choice as by making this method abstract we force all the sub classes to implement this method( otherwise you will get compilation error), also we need not to give any implementation to this method in parent class.