Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing class in the same package

Tags:

java

I went through some of topics, but didn't find a proper anser. I'm trying to import class to other class, but I get "The import "classname" cannot be resolved" error. Both classes are in the same package. What can cause the problem? I also tried to clean my project.

like image 289
Lobo Avatar asked Nov 17 '15 20:11

Lobo


People also ask

Do I need to import class in same package?

In Java, you do not need to add import statements for classes that exist within the same package (they are actually automatically “imported” by the compiler).

How do I use classes in the same package?

Classes and interfaces in the same package can use each other without prefixing their names with the package name. But to use a class or an interface from another package, you must use its fully qualified name, that is, packageName. anySubpackageName. ClassName .

Can I import same package class twice?

Yes, you can import a class twice in Java, it doesn't create any issues but, irrespective of the number of times you import, JVM loads the class only once.


1 Answers

If both classes are in same package, you don't have to import it.

like image 65
DBug Avatar answered Oct 28 '22 06:10

DBug