• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

package

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic