Skip to content
← Back to Community
Error in java package problem.
Profile icon
samba0648

While doing practice with packages I have got an error. Can anyone tell me what is the error and the solution? Thank You.

Answered by Coder100 [earned 5 cycles]
View Answer
Voters
Profile icon
samba0648
Comments
hotnewtop
Profile icon
Coder100

Instead of using package (that's for local files in a package), use import:

import mypack.*; class Main { public static void main(String[] args) { System.out.println("Hello world!"); Add obj = new Add(5,6); obj.sum(); } }

Note how you don't have to add mypack :)

read more

Profile icon
SixBeeps

The package keyword is for telling the compiler which package the current class belongs to. You made Main.java a part of the mypack package, but it should be packageless. Instead, replace package with import to be able to use the stuff in mypack.