This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

variable declaration

 
aravind kanna
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even though java automatically assigns value for varialbles why Error occurs if the variables are printed without initialised?
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm moving this to the Java In General (Beginner) forum.

I think what you're asking is this:

Even though java automatically assigns value for varialbles, why [does an] error occurs if the variables are printed without [first being] initialised?

.......................

Variables are given a default value if they are declared at a class level, but they are not assigned a value if they are declared locally (within a method). So you will receive an error if you try to use (for example, print) a local variable that you did not specifically assign a value to.


Check out this example to see what I'm talking about

[ January 06, 2005: Message edited by: Jessica Sant ]
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24204
34
Chrome Eclipse IDE Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java automatically initializes member variables, but not local variables; i.e.,

 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic