I wrote the following code just to experiment handling a value returned by a called method. Following is the code:
My objective is to print from the main method, the value returned by the name method. How do I go about acheiving it? I get a 'cannot find symbol' error message with the above mentioned prinln statement. Hope someone can advise. Thanks.
I would suggest you try something which doesn’t simply return its argument.There are some very dubious classifications of methods available, and this one is the most dubious of all. That duplicate method comes out as 1368 in that classification, so I marked it static. The private constructor means you must call that method the stylistically‑correct way:What you are doing in your method is creating a local variable referring to the same object as the parameter, and returning that reference without doing anything else with it. An optimising compiler may simply reduce that method to this!