• 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

Newbie question : package

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi. . I know package is used to group a collection of classes, but I got a
problem.
I saved the two classess as follows:
D:\JavaProgram\demo\myexercise\A.java
D:\JavaProgram\demo\myexercise\B.java
Program codes:
===============
package demo.myexercise;
public class A
{
String s;
public A()
{
s = "Hello";
}
public void getNum()
{
System.out.println(s);
}
}
==============
package demo.myexercise;
public class B
{
public static void main(String[] args)
{
A mya = new A();
mya.getNum();
}
}
Compiled A.java, no problem. but I got a problem when compiled B.java, it
said cannot resolve symbol...."A mya = new A()".
Why? Both A.java and B.java are saved under the same directory. Why B can't
call A?
What should I do if both A and B must be saved under the same directory?
Thanks.
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you still have to import the class for it to compile.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
From which directory are u compiling the program ??
U must compile it from path
D:\JavaProgram\
If u are compiling from some other direcory, then it wont work, as u will explicitely have to specify a classpath of "D:\JavaProgram\" while compilation which we dont want.
Hope this helps
-Dwipal
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic