aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Default values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Default values " Watch "Default values " New topic
Author

Default values

Anvi Dixit
Ranch Hand

Joined: Aug 28, 2006
Posts: 45
Hello

please find below the code:


now here i didnt intialize the variable keeping in my that the default value fo the int variable is 0. But i am getting an error (a red line) at line no 5 .
Please help me out though it is a very basic question.
Thanks
Anvi
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Do all primitive variables get default values? Read about it a bit and I am sure it would go a long way in helping you about default value assignment.
Andy Morris
Ranch Hand

Joined: May 30, 2004
Posts: 78
Local variables are not assigned default values, instance variables are.

Therefore having an int defined at that scope would not get the default value of 0 either. It would however if you'd put it outside of your method as an instance variable.

I'd recommend reading the compiler error, as it will say something like variable i may not have been initialised.
Asha Lilliete
Greenhorn

Joined: Jun 28, 2006
Posts: 6
All the local variables must be initialized.
where as a member variable neednt be, as it is initialiaed automatically.
If you initialize the byte b and compile it ,
the error should not occur.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9521
    
    2

Ok,

Why is that only local variables are not assigned default values and instance variables are?


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Default values