This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Two static methods with same name in two different classes Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Two static methods with same name in two different classes" Watch "Two static methods with same name in two different classes" New topic
Author

Two static methods with same name in two different classes

Santosh Kumar Nekkanti
Greenhorn

Joined: Feb 17, 2011
Posts: 8

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.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Two static methods with same name in two different classes
 
Similar Threads
Select & Convert Memory Stream Image to PDF File Using Aspose.Pdf
Help on testprogram and subclass please
Help with writing a remove() method
workflow implemetation with stateful session bean
JPA MappingException: Repeated column in mapping for entity