Let's learn java programming language with easy steps. This Java tutorial provides you complete knowledge about java technology.

Sunday 29 January 2017

Polymorphism in java

 Polymorphism

Polymorphism In Java

Polymorphism is derived from 2 greek words 'poly' and 'morphs'. The word poly means many and morphs mean behavior or form.

                                          Poly + Morphs   
                                             ↓               ↓              

                                          many    behavior or form = many behavior

Polymorphism in java is an oops concept, Whenever an object producing different-different behavior in different-different circumstances is called polymorphism in java.

Polymorphism is always achieved via behavior(member function) of an object. Properties(data member) of an object do not play any role in case of polymorphism. Polymorphism can be defined in other words "one name many forms".


Examples of polymorphism related to real life

(1) Related to person
  • Suppose you are in a classroom that time you behave like a student.
  • When you at your home at that time you behave like a son or daughter or brother.
  • When you are in a market, you behave like a customer.

(2) Related to product
  • Suppose Air Conditioner producing hot air in winter and cold air in summer.
So there is one name but producing different -different behavior in different circumstances.


Types of polymorphism in java, these are

  • Compile time or static polymorphism
  • Run time or dynamic polymorphism


Compile-time polymorphism

Method overloading (function overloading) and operator overloading both are compile time polymorphism. Method overloading(function overloading) or static binding(early binding ) is also known as compile time polymorphism in java.

"Whenever an object is bound with their functionality at compile time, this known as compile time polymorphism".


👉: Java does not support compile-time or static polymorphism. Java supports only dynamic polymorphism or run-time polymorphism.



Runtime polymorphism

Method overriding (function overriding) or Dynamic Binding(late binding) is known as runtime polymorphism in java. In java polymorphism principal is implemented with method overriding concept.

"Whenever an object is bound with their functionality at run-time, this known as run time polymorphism".


👉: Without inheritance concept method overriding is not possible in java So we will learn method overriding or dynamic binding after inheritance concept of oops.



Difference between Compile Time and Run Time Polymorphism  in Java

Compile-Time Polymorphism
  • In Compile Time polymorphism, call is resolved by the compiler.
  • Compile-Time polymorphism is also known as static binding, early binding, and overloading as well.
  • Overloading is compile time polymorphism, where more than one methods share the same name with different parameter or arguments.
  • Compile Time polymorphism is achieved by function overloading or method overloading and operator overloading.
  • It provides fast execution because known early at compile time.
  • Compile time polymorphism is less flexible as all thing executes at compile time.
Run-Time Polymorphism
  • In Run-Time polymorphism, call is not resolved by the compiler.
  • Run-Time polymorphism is also known as dynamic binding, late binding, and overriding as well.
  • Overriding is runtime polymorphism having the same method with same parameters or arguments but associated in a class and its subclass.
  • It is achieved by method overriding.
  • It provides slow execution as compared to early binding because it is known as run time.
  • Runtime polymorphism is more flexible because all thing executes at runtime.

Read More:


Share:

26 comments:

  1. Java is a high level, robust, secured and object-oriented programming language.The latest release of the Java Standard Edition is Java SE 8. Your post about polymorphism in java is really very informative. Wish to learn Java Training in Velachery enroll you in Login For Excellence

    ReplyDelete
    Replies
    1. Great Article android based projects

      Java Training in Chennai

      Project Center in Chennai

      Java Training in Chennai

      projects for cse

      The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

      Delete
  2. I just needed to record a speedy word to express profound gratitude to you for those magnificent tips and clues you are appearing on this site.
    http://www.traininginmarathahalli.in/core-java-training-in-bangalore/

    ReplyDelete
  3. Very Informative and insightful blog! This is so important to know about polymorphism in java I have been looking for this concept from many days and here i have found it in detail. This is good for beginner to know about polymorphism. Thanks for sharing!

    ReplyDelete
  4. That is very interesting; you are a very skilled blogger. I have shared your website in my social networks! A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article. Java Training in Chennai
    Java Training Institute in Chennai

    ReplyDelete
  5. Really awesome blog. Your blog is really useful for me. Thanks for sharing this informative blog. Keep update your blog...Java Training in Chennai
    Java Training Institute in Chennai

    ReplyDelete
  6. Nice blog..! I really loved reading through this article... Thanks for sharing such an amazing post with us and keep blogging...http://www.greenstechnologys.com/java-training-course-content.html

    ReplyDelete
  7. Great! Keep sharing such useful information. I think this is just the beginning & I'm looking forward to more meaningful blogs from you.

    white label website builder

    ReplyDelete
  8. Thanks a lot very much for the high quality and results-oriented help. I won’t think twice to endorse your blog post to anybody who wants and needs support about this area.
    Java Training in Chennai
    Java Training Institute in Chennai

    ReplyDelete
  9. I feel really happy to have seen your webpage and look forward to so many more entertaining times reading here. Thanks once more for all the details.
    Best Java Training Institute Chennai

    ReplyDelete
  10. You truly did more than visitors’ expectations. Thank you for rendering these helpful, trusted, edifying and also cool thoughts on the topic to Kate.
    Best Java Training Institute Chennai

    ReplyDelete
  11. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.

    Best RPA Training in Bangalore

    ReplyDelete
  12. I simply wanted to write down a quick word to say thanks to you for those wonderful tips and hints you are showing on this site.
    Java training institute in chennai

    ReplyDelete
  13. Thanks for sharing information with clear explanation. This is really awesome to understand.

    Thanks,
    Java Training in Chennai | Java Course in Chennai

    ReplyDelete
  14. The article is too good to learn in depth. Thanks for sharinng such useful information.

    Java training in Chennai

    ReplyDelete
  15. I believe there are many more pleasurable opportunities ahead for individuals that looked at your site.
    Click here:
    Online training in USA

    ReplyDelete
  16. Thanks for sharing information with clear explanation. This is really awesome to understand.
    Java training in Chennai |
    Tally training in Chennai"

    ReplyDelete

  17. Thank you for sharing such great information very useful to us.
    Java Training in Noida

    ReplyDelete
  18. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it. The angular js programming language is very popular which are most widely used.


    Dot Net Training in Chennai | Dot Net Training in anna nagar | Dot Net Training in omr | Dot Net Training in porur | Dot Net Training in tambaram | Dot Net Training in velachery





    ReplyDelete
  19. Fantastic blog with excellent information thanks for sharing found very useful thank you.
    typeerror nonetype object is not subscriptable

    ReplyDelete

Facebook Page Likes

Follow javatutorial95 on twitter

Popular Posts

Translate