我在使用Java中定義的類創建對象時遇到了錯誤。 這裏是我的代碼:在java中創建對象時給我一個錯誤
public class encapsulation {
class Emp
{
int empId;
String empName;
}
public static void main(String[]args)
{
Emp e1 = new Emp();
}
}
但它給我一個錯誤:
No enclosing instance of type encapsulation is accessible. Must qualify the allocation with an enclosing instance of type encapsulation (e.g. x.new A() where x is an instance of encapsulation).
這裏是一個screeshot:Error in object creation using java
謝謝。它的工作原理 –
@ErPriyatam很高興爲您服務。 – khelwood