Instace variable initialitation
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hey!
I am new to java and i have some question!Can you answer this?
Can I declare and initialize instance variable on separate lines?
Within a method( local variable )this code works for me
why this code generate some compiler error?I can't declare and initialize instance variable on separate lines,can I?
I am new to java and i have some question!Can you answer this?
Can I declare and initialize instance variable on separate lines?
Within a method( local variable )this code works for me
why this code generate some compiler error?I can't declare and initialize instance variable on separate lines,can I?
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
These links may help you out. Especially the second link:
http://leepoint.net/JavaBasics/methods/methods-22-local-variables.html
http://www.javaworld.com/javaworld/jw-03-1998/jw-03-initialization.html
Hope this helps.
http://leepoint.net/JavaBasics/methods/methods-22-local-variables.html
http://www.javaworld.com/javaworld/jw-03-1998/jw-03-initialization.html
Hope this helps.
Ryan Federwitz
Greenhorn
Posts: 3
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Thanks to your immediate response!
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
It is a compiler error because the second line is defined as a "statement". Statements are not permitted outside methods initialisers or constructors.
Ryan Federwitz
Greenhorn
Posts: 3
posted 16 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Thanks for your kindness Ritchie I think [ String str="string"; ] is a statement,but its worked!
This works well when the initialization value is available and the initialization can be put on one line.The compiler returns compiler error when the initialization value is available and the initialization can be put on separate line,
This works well when the initialization value is available and the initialization can be put on one line.The compiler returns compiler error when the initialization value is available and the initialization can be put on separate line,
| Paper jam tastes about as you would expect. Try some on this tiny ad: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |







