• Post Reply Bookmark Topic Watch Topic
  • New Topic

Two static methods with same name in two different classes  RSS feed

 
Santosh Kumar Nekkanti
Greenhorn
Posts: 8
Java
  • Mark post as helpful
  • send pies
  • 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.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!