1

I created a class HT17

package useFul;
class HT17 
{
    void show() 
    {
        System.out.println("Hello World!");
    }
}

And i tried accessing it from another class from same package

package useFul;
class HT18
{
    public static void main(String[] args) 
    {
        HT17 h =new HT17();
        h.show();
    }
}

But i am getting error: Cannot find symbol HT17 Yes, They are in same directory i.e useFul A solution would be helpful!

hthakkar8
  • 23
  • 1
  • 4

2 Answers2

1

At first create a folder named useFul and copy the classes there, then cmd to compile and run. cmd command:

 javac useFul/HT18.java
 java useFul/HT18
Rafiq
  • 740
  • 1
  • 5
  • 17
0

Most likely you are using javac <file name> this will create the class file in the same folder even though you have a package defined.

So you've to use javac -d . option this will create proper folder structure for the classes. Try the following.

$ javac HT17.java -d .
$ javac HT18.java -d .
$ java useFul.HT18

The -d is used to mention where to create the compiled classes with proper folder structure using package. in the example . is used, means use the current directory.

seenukarthi
  • 8,241
  • 10
  • 47
  • 68