Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

toString function override

919658Feb 23 2012 — edited Feb 23 2012
I am trying to override toString function as follows:

public void toString()
{
(isMale() ? "male " : "female ") + "elephant"
}

I want it to display the output of:

"male elephant" or "female elephant" based on the whether the boolean isMale is true or false. If it is true it would be the first option.

I keep getting the error:

Error: <identifier> expected

Thanks for any help I can get.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 22 2012
Added on Feb 23 2012
12 comments
242 views