• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Polymorphism and Static methods

 
Ramakrishna Gummadi
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ramakrishna Gummadi
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51349
87
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic