• Post Reply Bookmark Topic Watch Topic
  • New Topic

Newbie question : package  RSS feed

 
Jess Ishasder
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • 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.
 
Mark Stein
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you still have to import the class for it to compile.
 
Dwipal Desai
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!