File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

variable name in constructor

 
abalfazl hossein
Ranch Hand
Posts: 635
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Posts: 825
5
Java Python Ruby
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sergii Trotsenko
Greenhorn
Posts: 6
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
delete type declaration (double) on line 6.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47279
52
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sergii Trotsenko welcome to the Ranch
 
Sergii Trotsenko
Greenhorn
Posts: 6
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. If my answer was not in "Ranch style" please let me know
 
abalfazl hossein
Ranch Hand
Posts: 635
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sergii Trotsenko wrote:delete type declaration (double) on line 6.


It was nice point my friend. You are welcome!!Thanks all folks!!
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic