| Author |
Polymorphism and Static methods
|
Ramakrishna Gummadi
Greenhorn
Joined: Jun 29, 2011
Posts: 16
|
|
Please friends give me exact answers for my following questions....
1. polymorphism...... ?
2. is static polymorphism is there in java, if there means show me one code..?
3. can static methods overridden ?
|
 |
Wouter Oet
Saloon Keeper
Joined: Oct 25, 2008
Posts: 2700
|
|
|
Number 1 isn't a question but anyway for each of those topics is a huge amount of info out there. What don't you exactly get?
|
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
|
 |
Ramakrishna Gummadi
Greenhorn
Joined: Jun 29, 2011
Posts: 16
|
|
Wouter Oet wrote:Number 1 isn't a question but anyway for each of those topics is a huge amount of info out there. What don't you exactly get?
Actually i know polymorphism :- it is one of the OO principle, and polymorphism means like a person performing different tasks. In home as a father and in an organization as an employee.
Example :- methodoverriding
But i heared that polymorphism is two types dynamic and static polymorphism and examples for dynamic - method overriding and for static - method overloading..
1.According to my knowledge methodOverloading doesnot comes under polymorphism itself.
2.Another thing i heared in inheritance static methods are comes under static polymorphism.
so i want to know is there is static polymorphism ? and if there wil static methods in inheritance comes under static polymorphism ?
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32712
|
|
|
No, static members are not polymorphic. In fact you ought only to call static members by className.memberName, rather than on an object name.
|
 |
Ramakrishna Gummadi
Greenhorn
Joined: Jun 29, 2011
Posts: 16
|
|
Campbell Ritchie wrote:No, static members are not polymorphic. In fact you ought only to call static members by className.memberName, rather than on an object name.
yup.. static members called with help of classname.
But what about following code... here staticmethods luks like overriding ?
|
 |
Seetharaman Venkatasamy
Ranch Hand
Joined: Jan 28, 2008
Posts: 5575
|
|
Ramakrishna Gummadi wrote:
here staticmethods luks like overriding ?
did you read Wouter's response? Here in JavaRanch/Coderanch, there are lot of discussion about this. Please Search!
|
 |
goel Ashish
Greenhorn
Joined: May 14, 2011
Posts: 21
|
|
Ramakrishna Gummadi wrote:
Campbell Ritchie wrote:No, static members are not polymorphic. In fact you ought only to call static members by className.memberName, rather than on an object name.
yup.. static members called with help of classname.
But what about following code... here staticmethods luks like overriding ?
class Foo {
public static void classMethod() {
System.out.println(“classMethod() in Foo”);
}
public void instanceMethod() {
System.out.println(“instanceMethod() in Foo”);
}
}
class Bar extends Foo {
public static void classMethod() {
System.out.println(“classMethod() in Bar”);
}
public void instanceMethod() {
System.out.println(“instanceMethod() in Bar”);
}
}
class Test {
public static void main( String[] args) {
Foo f = new Bar();
f.instanceMethod();
f.classMethod();
}
}
Who says its over-riding?? When you execute the statement f.classMethod(); , It executes the foo's class method Which is not at all over riding, for in overriding subclass method is executed.
|
 |
 |
|
|
subject: Polymorphism and Static methods
|
|
|