public class Hassan {
int a = 0;
double b = 0.0;
String s = "Hello world";
public Hassan(int a){
this.s = "this is int";
}
public Hassan(double b){
this.s = "this is double";
}
public void shows(){
System.out.println(s);
}
public static void main(String[] args) {
// TODO 自动生成的方法存根
Hassan h1 = new Hassan(100);
h1.shows();
Hassan h2 = new Hassan(100.0);
h2.shows();
}
}
运行结果:
this is int
this is double
ERROR: JDWP Unable to get JNI 1.2 environment, jvm->GetEnv() return code = -2
JDWP exit error AGENT_ERROR_NO_JNI_ENV(183): [util.c:840]
你这个程序本身没有问题,是Debug导致出现的问题 ,解决方法网上很多:
http://blog.csdn.net/testcs_dn/article/details/42677269
文章中提到的链接也看一下(在main函数结束时,添加system.exit(0);)
使用Java Command Line和eclipse执行你的这段代码都没有问题。
你执行这段代码的是什么环境啊?
感觉你前面初始化是多余的
public class Test {
String s = "Hello world";
public Test(int a){
this.s = "this is int";
}
public Test(double b){
this.s = "this is double";
}
public void shows(){
System.out.println(s);
}
public static void main(String[] args) {
// TODO 自动生成的方法存根
Test h1 = new Test(100);
h1.shows();
Test h2 = new Test(100.0);
h2.shows();
}
}
this is int
this is double
没错啊
程序没有错误,可能是你的环境变量有点小问题