• Post Reply Bookmark Topic Watch Topic
  • New Topic

why method overloading is not polymorphism  RSS feed

 
anindya halder
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
As far as I know polymorphism is how how a single object can take different forms according to situations...
and static polymorphism can be achieved by method overloading and dynamic polymorphism can be achieved by method overriding?

I am ready KS book for SCJP exam......where its written method overloading is not polymorphism.......

Can anyone explain me why...........??

 
Keith Lynn
Ranch Hand
Posts: 2409
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In method overloading, you are creating a completely different method. The name is the same but it has a different parameter list. So it has no connection to an inherited method of the same name. I'm not sure what you mean by static polymorphism.
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
anindya halder wrote: . . . As far as I know polymorphism is how how a single object can take different forms according to situations...
. . .
No, it means a single method can take different forms …
 
Mansukhdeep Thind
Ranch Hand
Posts: 1163
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is nothing called static polymorphism as far as I understand. I don't know who coined that term. Read this article. Polymorphism is related to method overriding in Java i.e. when a class inherits a method of its parent class by extending it, and re-implements it in its own specific manner. Hence depending on the type of object at run-time, that class's method will be called.

@ Campbell : Have a look at this article. Don't you think he is talking non -sense when he says that method overloading is a type of polymorphism? Isn't he wrong? Or is my understanding flawed?
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are different types of polymorphism, and different conventions for the definition. Some people consider overloading to be a form a polymorphism, and others don't. To my knowledge, there is no one widely agreed upon standard. You can debate up down and sideways which view is "correct," but it's a rather pointless argument. (Unless you find that kind of thing amusing. )
 
Mansukhdeep Thind
Ranch Hand
Posts: 1163
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:There are different types of polymorphism, and different conventions for the definition. Some people consider overloading to be a form a polymorphism, and others don't. To my knowledge, there is no one widely agreed upon standard. You can debate up down and sideways which view is "correct," but it's a rather pointless argument. (Unless you find that kind of thing amusing. )


Is it? I believe that the rules/ definitions of a computer language are pretty much stated in black and white. Rare to to see someone, that too you Jeff, remarking that something can be defined as per someone's liking.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mansukhdeep Thind wrote:
Jeff Verdegan wrote:There are different types of polymorphism, and different conventions for the definition. Some people consider overloading to be a form a polymorphism, and others don't. To my knowledge, there is no one widely agreed upon standard. You can debate up down and sideways which view is "correct," but it's a rather pointless argument. (Unless you find that kind of thing amusing. )


Is it? I believe that the rules/ definitions of a computer language are pretty much stated in black and white. Rare to to see someone, that too you Jeff, remarking that something can be defined as per someone's liking.


First, this has nothing to do with "rules/definitions of a computer language." It's about the definition of a general CS term, outside of the rules of any specific language.

Second, you're missing the point. For some things there exist well-established, widely-agreed-upon standard definitions. For other things, there exist several commonly used definitions, with no one of them being the clear winner as "the" definition. The term "polymorphism" is in the second category, in my experience.

Having said that, if the JLS defines polymorphism a certain way for Java, and is consistent with that definition, then, yes, that is the one correct definition for Java. The above still applies for the term in general though. (And as it turns out, neither of the 2 most recent JLSes have "polymorphism" in their index, so it probably doesn't define the term specially for Java.)

 
Mansukhdeep Thind
Ranch Hand
Posts: 1163
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote:
Mansukhdeep Thind wrote:
Jeff Verdegan wrote:There are different types of polymorphism, and different conventions for the definition. Some people consider overloading to be a form a polymorphism, and others don't. To my knowledge, there is no one widely agreed upon standard. You can debate up down and sideways which view is "correct," but it's a rather pointless argument. (Unless you find that kind of thing amusing. )


Is it? I believe that the rules/ definitions of a computer language are pretty much stated in black and white. Rare to to see someone, that too you Jeff, remarking that something can be defined as per someone's liking.


First, this has nothing to do with "rules/definitions of a computer language." It's about the definition of a general CS term, outside of the rules of any specific language.

Second, you're missing the point. For some things there exist well-established, widely-agreed-upon standard definitions. For other things, there exist several commonly used definitions, with no one of them being the clear winner as "the" definition. The term "polymorphism" is in the second category, in my experience.

Having said that, if the JLS defines polymorphism a certain way for Java, and is consistent with that definition, then, yes, that is the one correct definition for Java. The above still applies for the term in general though. (And as it turns out, neither of the 2 most recent JLSes have "polymorphism" in their index, so it probably doesn't define the term specially for Java.)



Hmm... Lets stick to what the JLS says. Just to make me happy Jeff.
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mansukhdeep Thind wrote:Hmm... Lets stick to what the JLS says. Just to make me happy Jeff.

In that case, you should stop talking about polymorphism, because the JLS does not provide any definition of that term. As Jeff said.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1163
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Simmons wrote:
Mansukhdeep Thind wrote:Hmm... Lets stick to what the JLS says. Just to make me happy Jeff.

In that case, you should stop talking about polymorphism, because the JLS does not provide any definition of that term. As Jeff said.


In fact, I should stop talking Mike. Went for a 10 km run today. Pretty tired. Good night..
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mansukhdeep Thind wrote:
Hmm... Lets stick to what the JLS says. Just to make me happy Jeff.


Believe it or not, making you happy is not my main priority.

And as I already pointed out, the JLS doesn't seem to have anything to say on the matter. Please pay closer attention in the future. Thanks.
 
anindya halder
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mansukhdeep Thind wrote:There is nothing called static polymorphism as far as I understand. I don't know who coined that term. Read this article. Polymorphism is related to method overriding in Java i.e. when a class inherits a method of its parent class by extending it, and re-implements it in its own specific manner. Hence depending on the type of object at run-time, that class's method will be called.

@ Campbell : Have a look at this article. Don't you think he is talking non -sense when he says that method overloading is a type of polymorphism? Isn't he wrong? Or is my understanding flawed?


Got the idea.thanks a ton!!
 
Campbell Ritchie
Marshal
Posts: 56533
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mansukhdeep Thind wrote: . . . Campbell : Have a look at this article. . . .
That is actually quite a good article; he does not say that overloading is polymorphism, but that it follows the principles of polymorphism. I would have preferred him to say overriding and overloading are analogous to each other.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1163
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeff Verdegan wrote: And as I already pointed out, the JLS doesn't seem to have anything to say on the matter. Please pay closer attention in the future. Thanks.


Yes, have to learn this one thing from you. You do have a keen eye for detail.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1163
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
Mansukhdeep Thind wrote: . . . Campbell : Have a look at this article. . . .
That is actually quite a good article; he does not say that overloading is polymorphism, but that it follows the principles of polymorphism. I would have preferred him to say overriding and overloading are analogous to each other.


Yes ,he does say that Campbell.

Java has excellent support of polymorphism in terms of Inheritance, method overloading and method overriding.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!