Polymorphism in Java : Part 1

When i started understanding Polymorphism, one sentence that many people ( infact my college profs) told me was it refers to One Object, many forms. I could never understand this till i actually starting giving it a serious thought ( and that was some years later). Today, here at Technofriends blog, I would like to share my knowledge on Polymorphism and how it is implemented in Java.

I shall primarily be talking about

  1. Polymorphism as a concept in OOPS
  2. How is Polymorphism achieved in Java?
  3. What is meant by method Overloading and Overriding?
  4. What are the conditions for Overloading and Overriding methods in Java?

Polymorphism

Lets start talking about this whole Polymorphism thing first. Polymorphism as many would have already told you (like it happened with me) refers to One Object, Many forms. That means, Polymorphism is the ability of one object to be treated and used like other object.

In Java, Polymorphism is manifested in the form of multiple methods having the same name. In this post, i shall only be concentrating on the basic concepts and will be talking more about Polymorphism in my next posts. My idea is to make the readers understand Polymorphism and help them in applying it in their respective projects.

Concepts like method overloading and method overriding are the primary concepts often being heard of whenever we talk about Polymorphism.

Method Overloading or compile time polymorphism allows us to have same method name in a class or a subclass, however, the class / subclass method ( overloaded method) should change the argument compulsarily. This brings us to the conclusion that overloaded methods may all be defined in the same class, or they may be defined in different classes as long as those different classes share a superclass- subclass relationship.

More specifically, here is what Roberts, Heller, and Ernest have to say about overloading methods in their excellent book entitled The Complete Java 2 Certification Study Guide:

“A valid overload differs in the number or type of its arguments. Differences in argument names are not significant. A different return type is permitted, but is not sufficient by itself to distinguish an overloading method.”

Therefore, this brings us to the end of the basics of Method Overloading. In my next post, i shall be talking about

  • How is method overloading achieved?
  • What are the criteria’s for a valid overloading?
  • Why is method overloading called Compile time polymorphism?

Do stay tuned to Technofriends for more, one of the best ways of doing so if by subscribing to our feeds. You can subscribe to Technofriends feed by clicking here.


Related Reads:

Polymorphism in Java : Part 2

 

Cheers

Vaibhav

Advertisements

3 Responses

  1. […] entry was written by Vaibhav Pandey–>Technofriends Team. Bookmark the permalink. Follow any comments here with the RSS feed for this post.Content related […]

  2. […] Polymorphism in Java : Part 1 […]

  3. […] Also read:Understanding Polymorphism in Java : Part 1 […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: