Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why i am getting this copile time error

 
Neha Sawant
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why i am getting this error?
the method String toString() declared in class String should not be overide the method of the same signature declared in java.lang.object.They must havr thesame return type
public String toString()
/\
even though i have not wrtiien any toString method

public class Test1{
int temp;
Test1 Test1(){this.temp=10;
return this;
}
public static void main(String args[]){
Test1 t1=new Test1();
Test1 t2=t1.Test1();
if (t1==t2){
System.out.println("EQUAL");
}
else{ System.out.println("NOT EQUAL");
}
}
}

same error for this code also
public class Switch{
public static void main(String args[]){

int i='c';
switch(i){
case 'c': System.out.println("!!!");
break;
default : System.out.println(i);
break;
}
}

 
Jennifer Warren
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried both they are working fine. Need to check the way ur running or compiling it.
Which JDK version are u using.
Thanks.
Jennifer.
 
Neha Sawant
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Jennifer ,
I am using jdk1.2.2
Regards
Neha
 
Neha Sawant
Ranch Hand
Posts: 204
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey,
i got it.
My mistake
Sorry
Neha
 
Jennifer Warren
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is working fine on jdk1.3.
Jennifer.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic