Exceotion in thread "main" Java.lang.NoclassDefFound Error( java解释出错)

下面程序在运行时出现题中所述的错误:

(该程序用来验证JAVA程序中成员变量的初始化规律)
java源代码:
public class InitDemo {
        public static int i;
	public int j;
	public boolean b;
	public String name;
	public void show() {
		System.out.println(i);
		System.out.println(j);
		System.out.println(name);
		System.out.println(b);
		
	}
}

class test {
	public static void main(String[] args) {
		InitDemo obj1 = new InitDemo();
		obj1.show();
	}

}


出现错误:Exceotion in thread "main" Java.lang.NoclassDefFound Error( java解释出错)
出错原因:
应该将 public static void main(String[] srgs){}所在的类作为public类,在本题中应该将class Test改为public class Test
修改后的代码为:

class InitDemo {
	public static int i;
	public int j;
	public boolean b;
	public String name;
	public void show() {
		System.out.println(i);
		System.out.println(j);
		System.out.println(name);
		System.out.println(b);
		
	}
}

public class Test_InitDemo {
	public static void main(String[] args) {
		InitDemo obj1 = new InitDemo();
		obj1.show();
	}

}

运行结果为:

Exceotion in thread

 
  
 
  
 
  
 
  
 
  
 
  
 
  
 
  
 
  
 
  
 
  
 
  
 
  
 
 

你可能感兴趣的:(Exceotion in thread "main" Java.lang.NoclassDefFound Error( java解释出错))