• Post Reply Bookmark Topic Watch Topic
  • New Topic

toString metthod overriding  RSS feed

 
bairava surya
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you have a question?
 
bairava surya
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this program doesnt compile?
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bairava surya wrote:this program doesnt compile?


Are you asking if the program compiles? ,,,

Isn't it easier to just try to compile it?

Henry
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And if it doesn't compile, and you're asking why, maybe you should tell us what the error message is?
 
bairava surya
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
it is showing error as illegal character \160
 
Campbell Ritchie
Marshal
Posts: 56529
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That suggests you have been using a word processor rather than a text editor. Find out what \160 is: look in the Unicode website for it; I think it is \u0070. But that comes out as p so it must be 160 in decimal not octal so try \u00a0 instead and see what that is.

By the way, your choice of names for your types and variables is really bad. This1?

Please indent your code consistently and put one blank like before each method or constructor. It is difficult to read as it is.
 
S Majumder
Ranch Hand
Posts: 349
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bairava,
Let me try to explain ..

In main() you are creating one object of type This1 by using new This1() .When the object is being created it is calling the no-arg constructor , now here is the trick .In the constructor


System.out.println(this) means it is calling the This1 object and internally calling the overridding toString() .
We are getting the expected output as :TestClasssi10

Hope you understand .

Thanks ,
Satya
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!