Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Runtime Polymorphism

 
Sathish Kumar Govindan
Greenhorn
Posts: 18
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RunTime Polymorphism cannot be applied to static methods and variables


Can anybody explain what the above statement depicts?


Thanks in advance,
G.Sathish kumar
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RunTime Polymorphism cannot be applied to static methods and variables


as static variables and methods are bound to class and not to objects, polymorphism is not possible.


Hope this helps
 
Sathish Kumar Govindan
Greenhorn
Posts: 18
Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Dude
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Amit Ghorpade:

as static variables and methods are bound to class and not to objects, polymorphism is not possible.


Well, first, in Java (as in any other language I know), runtime polymorphism doesn't apply to member variables either.

Second, there are languages out there where classes are objects, too, and therefore class methods are also polymorphic. Just not in Java.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Ilja Preuss]:[...]in Java (as in any other language I know), runtime polymorphism doesn't apply to member variables either.

In Scala member values not explicitly declared private are inherited and overridable. As a matter of fact its a common idiom in Scala to eschew passing in arguments to a constructor in favor of creating an anonymous subclass and overriding specific values.
 
Amit Ghorpade
Bartender
Posts: 2854
10
Fedora Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ilja Preuss


Second, there are languages out there where classes are objects, too, and therefore class methods are also polymorphic. Just not in Java

I am unaware about other OO languages, except Java and C++.
So I was talking in context of Java
[ June 15, 2008: Message edited by: Amit Ghorpade ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic