刚刚学习JAVA,编写了2个小程序,求大神指教错误的那个程序是哪里错了,为什么?该怎么写才正确?
程序1:编译通过,运行结果为“true”.publicclassTest827{publicstaticvoidmain(Stringargs[]){Testt1=new...
程序1:编译通过,运行结果为“true”.
public class Test827{
public static void main(String args[]){
Test t1=new Test("asd");
Test t2=new Test("asd");
System.out.println(t1.str.equals(t2.str));
}
}
class Test{
String str;
Test(String str){
this.str=str;
}
}
程序2:编译出错!!!
public class Test0827{
public static void main(String args[]){
Test t1=new Test(10);
Test t2=new Test(10);
System.out.println(t1.i.equals(t2.i));
}
}
class Test{
int i;
Test(int i){
this.i=i;
}
}
编译错误提示:
---------- 编译 ----------
Test0827.java:5: 错误: 无法取消引用int
System.out.println(t1.i.equals(t2.i));
^
1 个错误
Output completed (1 sec consumed) - Normal Termination 展开
public class Test827{
public static void main(String args[]){
Test t1=new Test("asd");
Test t2=new Test("asd");
System.out.println(t1.str.equals(t2.str));
}
}
class Test{
String str;
Test(String str){
this.str=str;
}
}
程序2:编译出错!!!
public class Test0827{
public static void main(String args[]){
Test t1=new Test(10);
Test t2=new Test(10);
System.out.println(t1.i.equals(t2.i));
}
}
class Test{
int i;
Test(int i){
this.i=i;
}
}
编译错误提示:
---------- 编译 ----------
Test0827.java:5: 错误: 无法取消引用int
System.out.println(t1.i.equals(t2.i));
^
1 个错误
Output completed (1 sec consumed) - Normal Termination 展开
2个回答
2016-08-28
展开全部
public class Test827{
public static void main(String args[]){
Test t1=new Test("asd");
Test t2=new Test("asd");
System.out.println(t1.str.equals(t2.str));
}
}
class Test{
String str;
Test(String str){
this.str=str;
}
}
public class Test0827{
public static void main(String args[]){
Test t1=new Test(10);
Test t2=new Test(10);
System.out.println(t1.i==t2.i);
}
}
class Test{
int i;
Test(int i){
this.i=i;
}
}
public class Test08272{
public static void main(String args[]){
Test t1=new Test(10);
Test t2=new Test(10);
System.out.println(t1.i.equals(t2.i));
}
}
class Test{
Integer i;
Test(int i){
this.i=i;
}
}
public static void main(String args[]){
Test t1=new Test("asd");
Test t2=new Test("asd");
System.out.println(t1.str.equals(t2.str));
}
}
class Test{
String str;
Test(String str){
this.str=str;
}
}
public class Test0827{
public static void main(String args[]){
Test t1=new Test(10);
Test t2=new Test(10);
System.out.println(t1.i==t2.i);
}
}
class Test{
int i;
Test(int i){
this.i=i;
}
}
public class Test08272{
public static void main(String args[]){
Test t1=new Test(10);
Test t2=new Test(10);
System.out.println(t1.i.equals(t2.i));
}
}
class Test{
Integer i;
Test(int i){
this.i=i;
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询