| Author |
Runtime Polymorphism
|
Sathish Kumar Govindan
Greenhorn
Joined: Jan 23, 2007
Posts: 17
|
|
RunTime Polymorphism cannot be applied to static methods and variables
Can anybody explain what the above statement depicts? Thanks in advance, G.Sathish kumar
|
SCJP 5.0, SCWCD JEE5
|
 |
Amit Ghorpade
Bartender
Joined: Jun 06, 2007
Posts: 2551
|
|
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
|
SCJP, SCWCD.
|Asking Good Questions|
|
 |
Sathish Kumar Govindan
Greenhorn
Joined: Jan 23, 2007
Posts: 17
|
|
|
Thanks Dude
|
 |
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
|
|
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.
|
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
|
 |
Garrett Rowe
Ranch Hand
Joined: Jan 17, 2006
Posts: 1295
|
|
[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.
|
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
|
 |
Amit Ghorpade
Bartender
Joined: Jun 06, 2007
Posts: 2551
|
|
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 ]
|
 |
 |
|
|
subject: Runtime Polymorphism
|
|
|