April 04, 2012

Real world example for Abstract Class in java


Real world example for Abstract Class in java


Abstract class is a class that contains abstract method and non abstract methods. Sub class which extends the abstract class "must" implements the abstract methods in the abstract class.
For examples.
Let us consider animal as our abstract class. I wrote 2 function in it. One breath() , breath is a non abtract method.
please consider every animal breath in a common way. so i write some code inside the function breath(). let it be a "Through respiratory system"

second function is a abstract method lifespan(), lifespan is different for each types of animals.

now consider sub class as dog , cat and ant

these class extends that abstract class. The relation ship will come in this way like dog is an animal, cat is a animal ..."is - a" relation ship
since the sub class extends the base class animal.. we need to define lifespan() function in each subclass.

lifespan() is different for each animal

for cat its 25, dog 22 and ant 3.

while i create an object Animal a = new cat();
a.breath()  will return me   "Through respiratory system" and
a.lifespan() will return me  25

if i create an object Animal a = new dog();
a.breath() ---->  "Through respiratory system"
a.lifespan() -----> 22

got it !!!!


Author +belazy 


Thanking you...................

17 comments:

  1. Replies
    1. Thanks Padmanabham Vishwakarma

      Delete
  2. Then what it the difference from the concept of interface?

    ReplyDelete
    Replies
    1. Only abstract methods are used.
      http://javabelazy.blogspot.in/2012/01/how-to-reduce-coupling-in-java.html

      Delete
  3. Understood the concept. Thank u so much

    ReplyDelete
  4. amazing explanation.............give the list of java interview question list with the best real life example.

    ReplyDelete
    Replies
    1. http://javabelazy.blogspot.in/2012/11/find-missing-number-in-sequence.html

      Like this (aptitude questions)

      Delete
  5. Hey there! Someone in my Facebook group shared this website with us so I came to give
    it a look. I'm definitely enjoying the information. I'm book-marking
    and will be tweeting this to my followers! Excellent blog and terrific
    design.

    Look into my webpage - frontier internet service provider

    ReplyDelete
  6. I am in fact pleased to glance at this blog posts which carries lots of useful information, thanks for providing these kinds of statistics.


    Review my web site - www.prbuzz.com

    ReplyDelete
  7. Hello my family member! I wish to say that this post
    is amazing, great written and include approximately all important infos.

    I'd like to peer more posts like this .

    Also visit my page: www.sbwire.com
    my page :: www.emailwire.com

    ReplyDelete
  8. If you are going for finest contents like me,
    simply go to see this site all the time since
    it offers quality contents, thanks

    my web-site :: http://www.emailwire.com/
    My web site > http://www.sbwire.com

    ReplyDelete
  9. I am genuinely delighted to glance at this website posts which includes plenty of useful facts, thanks for providing these data.


    my blog post ... frontier wireless internet
    Also see my web page: emailwire.com

    ReplyDelete
  10. Excellent !!! Understood the concept clearly ! :)

    ReplyDelete
  11. AnonymousMay 24, 2013

    Hello thеrе! Do уou use
    Tωitter? I'd like to follow you if that would be ok. I'm undoubtedly
    enjoying yоur blog and look forward to neω posts.


    Tаke а look at my ωebsitе - diamondlinks review

    ReplyDelete

Your feedback may help others !!!

Facebook comments