Import doesn't work
JVM cannot access custom classes when using * in import statement.
My classpath is export CLASSPATH =.: / Home / aksharaaaa / Documents / programs / core_java / class_java:
I first created the Employee.java file as a package, i.e.,.
package com.durgasoft.core;
public class Employee
{
int eid;
String ename;
double esal;
public Employee(int eid1, String ename1, double esal1)
{
eid=eid1;
ename=ename1;
esal=esal1;
}
public void getEmployeeDetails()
{
System.out.println("Employee Details");
System.out.println("-------------------");
System.out.println("Eno:"+eid);
System.out.println("Ename:"+ename);
System.out.println("ESalary"+esal);
}
}
To compile this file I used the following command: "javac -d .. Employee.java" then the com / durgasoft / core / Employee.class file was created in the class_java folder.
then i created a file test.java in class_java folder with only the following code.
import com.durgasoft.core.*;
public class test{
public static void main(String[] args){
Employee e= new Employee(111, "viay", 3333.333);
e.getEmployeeDetails();
}
}
when i compile the test.java file then the JVM raises the following error
<b>test.java:5: error: constructor Employee in class Employee cannot be applied to given types;
Employee e= new Employee(111, "viay", 3333.333);
^
required: no arguments
found: int,String,double
reason: actual and formal argument lists differ in length
test.java:6: error: cannot find symbol
e.getEmployeeDetails();
^
symbol: method getEmployeeDetails()
location: variable e of type Employee 2 errors
If I use a fully qualified name, that is, import com.durgasoft.core.Employee; in the test.java file then JVM can compile and run ...
source to share
It looks like you are taking another class from your class. I can happen and it's confusing. I've been in this situation several times and usually JWhich can help. It tells you which class you are using exactly. You can use a utility or source code. It's so small and easy - I always use it in my projects and codebase and use it to disambiguate.
source to share