• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Polymorphism and Static methods

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?

 
Marshal
Posts: 72921
330
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Anything worth doing well is worth doing poorly first. Just look at this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic