Your executable statements are loose in the class body - they should be in an executable block, a constructor, or a method. Only the first line is valid in that context, the declaration of 'relations' as a private member (or property) of the class. Pho Tek showed the use of a code block that will execute when a new instance of the class is created.
SCJP 1.5
Jinny Morris
Ranch Hand
Joined: Apr 29, 2007
Posts: 101
posted
0
Pho Tek and Greg -
Thank you very much! Yes, I tried putting the statements in a code block and it worked! I had read that executable statements couldn't be "loose" in a class body, but just hadn't made the association. Now I will probably remember ...
Thanks for the reference. Since my whole reason for trying to learn Java was my total incompetence at OOP, this one only took about 15 mins of reading to become a bookmark ...
veda vyas sista
Greenhorn
Joined: Sep 21, 2007
Posts: 10
posted
0
i have a small doubt you said after the private declaration all the statements should be in braces but why please tell me clearly because it is only a declaration of a string of array but not a method then why to use braces.
veda vyas sista
Greenhorn
Joined: Sep 21, 2007
Posts: 10
posted
0
one more doubt while printing an array why can't we use or print the elements directly for example :
if i write like this iam getting an error
class Test { public static void main(String[] argv) {
but if i use only one array or i use for loop it is working why ?
iam new to forum if i do any mistakes in posting please forgive me but reply me
Jinny Morris
Ranch Hand
Joined: Apr 29, 2007
Posts: 101
posted
0
If I try your program, but instead of this argument list (string, string) I use: it works.
If you look up the method println in the API, the type of thing printed out is optional, but the number of arguments given is always just one. So if you use a loop of some kind and a series of statements like
it will work.
Your other option is to use the format method of the String class to format your output before you print it.
Nicholas Jordan
Ranch Hand
Joined: Sep 17, 2006
Posts: 1282
posted
0
[veda vyas sista :]why please tell me clearly because it is only a declaration of a string of array but not a method then why to use braces.
Because what the compiler does, after a few prep steps, is the functional equivalent of running some execuatable code.
[ September 23, 2007: Message edited by: Nicholas Jordan ]
"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."