'Importing class in the same package
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.
Solution 1:[1]
If both classes are in same package, you don't have to import it.
Solution 2:[2]
Myclass.java
package mypackage;
import java.util.*;
public class Myclass{
public static void add(int a,int b){
System.out.println(a+b);
}
public static void main(String[] args){
System.out.println("success");
}
}
Good.java
class Good{
public static void main(String [] args){
Myclass obj = new Myclass();
obj.add(2,3);
}
}
I tried to use add method in "Good" class from "Myclass" class but it is not working this way. What is wrong in this method?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | DBug |
| Solution 2 | Deepak Silver |
