当前位置: 技术问答>java相关
一段小小的Java程序,请指点指点!!!多谢!
来源: 互联网 发布时间:2015-04-24
本文导语: 程序: public class MyClass { public static int instanceCount; public MyClass(){ instanceCount++; } static{ instanceCount = 0; } } 执行编译: C:jdk1.3demoMyJavaProgram>javac MyClass.java C:jdk1.3demoMyJavaProgram>java MyClass Exception in thread "main"...
程序:
public class MyClass {
public static int instanceCount;
public MyClass(){
instanceCount++;
}
static{
instanceCount = 0;
}
}
执行编译:
C:jdk1.3demoMyJavaProgram>javac MyClass.java
C:jdk1.3demoMyJavaProgram>java MyClass
Exception in thread "main" java.lang.NoSuchMethodError: main
C:jdk1.3demoMyJavaProgram>
请问这是什么意思?
如何改进???
多谢指点!
public class MyClass {
public static int instanceCount;
public MyClass(){
instanceCount++;
}
static{
instanceCount = 0;
}
}
执行编译:
C:jdk1.3demoMyJavaProgram>javac MyClass.java
C:jdk1.3demoMyJavaProgram>java MyClass
Exception in thread "main" java.lang.NoSuchMethodError: main
C:jdk1.3demoMyJavaProgram>
请问这是什么意思?
如何改进???
多谢指点!
|
public class MyClass {
public static int instanceCount;
public MyClass(){
instanceCount++;
}
static{
instanceCount = 0;
}
public static void main(String[] args)
{
//在这里做你想做的事情
MyClass t=new MyClass();
System.out.println(t.instanceCount);
}
}
public static int instanceCount;
public MyClass(){
instanceCount++;
}
static{
instanceCount = 0;
}
public static void main(String[] args)
{
//在这里做你想做的事情
MyClass t=new MyClass();
System.out.println(t.instanceCount);
}
}
|
没有执行入口:
public static void main(String[] args){
}
方法
public static void main(String[] args){
}
方法