Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Two static methods with same name in two different classes

 
Greenhorn
Posts: 8
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai,
         I learnt that ,whenever we call a static method from another static method we call it directly using its method name without using any object of the class in which that method resides.But now my doubt is what if we have same method name which is also static resides in other class. Now won't the compiler gets confused to which method it should go when we call one of those methods since they have same name and we are not refering them using their class objects ?

Thanks,
Santosh N.
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm guessing your question is about static imports? There is no way to call a static method in another class without using the class name, unless you statically import the method. When you use multiple static imports of the same name you get a compilation error because the method is ambiguous. If your class contains a static method with the same name, that is the one called and the static imports are ignored.
 
On my planet I'm considered quite beautiful. Thanks to the poetry in this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic