What I have is two package emp and p5. I have one file consisting two classes one of them is public and another is default.
package emp;
public class Employee{
public void display(){
System.out.println("from DebarredEmply");
}
}
class DebarredEmployee{
public void display(){
System.out.println("from DebarredEmply");
}
}
what I want to is create the object of DebarredEmployee in class lying in another package.
package p5;
import emp.DebarredEmployee;
class Test{
public static void main(String[] args){
DebarredEmployee dEmp = new DebarredEmployee();
dEmp.display();
}
}
I have tried above approach but it is giving me the error
error: DebarredEmployee is not public in emp; cannot be accessed from outside package
So how can I create the object of the class I want.
ps:
I know defaults are not accessible outside the package and it will work if I make the class public and move it another file, I want to do that without making new file and keeping the access modifier as default one. –sorry for some sloppy naming conventions.