Forums Register Login

toString metthod overriding

+Pie Number of slices to send: Send
+Pie Number of slices to send: Send
Did you have a question?
+Pie Number of slices to send: Send
this program doesnt compile?
+Pie Number of slices to send: Send
 

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
+Pie Number of slices to send: Send
And if it doesn't compile, and you're asking why, maybe you should tell us what the error message is?
+Pie Number of slices to send: Send
it is showing error as illegal character \160
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
If you want to look young and thin, hang around old, fat people. Or this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 453 times.
Similar Threads
Metthod within method need sloving
static with 'this' ??
Strings....
Which Access Modifier when override toString()?
Wrapper Class Object Doubt
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 04:28:35.