| Author |
variable name in constructor
|
abalfazl hossein
Ranch Hand
Joined: Sep 06, 2007
Posts: 602
|
|
This code is wrong, I know it is because amount has the same name, But I don't know what happened actually!
It shows:
name;Amir Account profit for one year=0.0
Amir shows despite same variable, But amount is 0!!
May some one explain more?
|
 |
Kemal Sokolovic
Bartender
Joined: Jun 19, 2010
Posts: 792
|
|
You are declaring amount again in your constructor at line 6. This declaration hides your field, so that amount represents variable local to the constructor, and the value is never assigned to the field it should be assigned to.
Edit: Actually, that code shouldn't even compile. Constructor name does not match class name.
|
The quieter you are, the more you are able to hear.
|
 |
Sergii Trotsenko
Greenhorn
Joined: Oct 23, 2012
Posts: 6
|
|
|
delete type declaration (double) on line 6.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32712
|
|
Sergii Trotsenko welcome to the Ranch
|
 |
Sergii Trotsenko
Greenhorn
Joined: Oct 23, 2012
Posts: 6
|
|
Thanks. If my answer was not in "Ranch style" please let me know
|
 |
abalfazl hossein
Ranch Hand
Joined: Sep 06, 2007
Posts: 602
|
|
Sergii Trotsenko wrote:delete type declaration (double) on line 6.
It was nice point my friend. You are welcome!!Thanks all folks!!
|
 |
 |
|
|
subject: variable name in constructor
|
|
|