• 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

import - giving problems

 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have three directories like this
c:\java
c:\java\p1
c:\java\p2

I have class A in package p1 and class B in package p2. What is the statement to import A to B? Also, if there is a package variable i in A, can i use it in B?
I have give the code snippets below.
<code>
package p2;
import p1.*;
public class B
{
A a=new A();
System.out.println(a.i);
}
------------------------------------------------------
package p1;
public class A
{
int i=10;
}
</code>

I am told that only if the variable i is public can i access it as a.i. Then what is the meaning of import. Does import give access only to public variables(that negates the meaning of public... )

------------------
Regards,
Shree
[This message has been edited by shree vijay (edited December 23, 2000).]
[This message has been edited by shree vijay (edited December 23, 2000).]
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The import statement has nothing to do with access. All an import statement does is let you use simple names like A instead of the full name p1.A.
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Ran. It is same thing as #include<___.h> in c/c++.
To use the variable they must be specified as a public to acess them from other packages.
Wishes for happy christmas and new year
 
shree vijay
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, guys.
------------------
Regards,
Shree
 
reply
    Bookmark Topic Watch Topic
  • New Topic