• Post Reply Bookmark Topic Watch Topic
  • New Topic

package  RSS feed

 
amit bhadre
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How the JVM recognizes the classes of same name with having same name constructor located in different packages say eg: pack1,pack2 ?

e.g:
1) In pack1:-

import pack1;
class A{
void A(){
System.out.println("pack1");
}
}

2) In pack2:
class A{
void A(){
System.out.println("pack2");
}
}

And now I calling both in main....

class callPack{
public static void main(String args[]){
A a=new A();
a.A();
}
}
If any syntax mistake in packages is there rectify plz.....

Here by question is how the a member variable calls the methods/constructors with single Instance/reference to both packages?
Here doesn't it require another one to call? If it doesnt need how it shares the Object? And what percentage of each packages share the object?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16057
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have two classes with the same name in different packages, you will need to specify the fully qualified names of the classes in the code where you're using both. The compiler has no way of finding out automatically what you mean (it can't read your mind...).

An example from the JDK are classes java.util.Date and java.sql.Date. Note that you can't import both classes at the same time - the compiler will give you an error if you try.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!