Hi,
OK, Here is your solution:
<SNIP YOUR CODE>
public class StaticField2{
public static void main(String args[]){
private int x, y; // <<== error 1 (SPG: All variables declared inside a
method are private to that method. JAVA does not allow you to modify this.)
for ( y = 0 ; y < 100 ; y++){
x = StaticMethod();
System.out.prin tln(" x = "+x);
}
}
public static int StaticMethod(){
private static int m = 0; // <<== error 2 (SPG: Cannot keep a static
variable inside a method)
m = m++;
return m;
}
}
</SNIP>
So, To acheive your solution I would imagine you need to do this:
public class StaticField2{
private static int m = 0; // <= Static variable declared global to the
class only.. All methods have access to the single instance
public static void main(String args[]){
int x, y; //<= BOTH ARE LOCAL VARIABLES TO THE MAIN METHOD
for ( y = 0 ; y < 100 ; y++){
x = StaticMethod();
System.out.prin tln(" x = "+x);
}
}
public static int StaticMethod(){
m = m++;
return m;
}
}
I hope this helps you..
Steve
"IHateSuper man" <Wh*@you.care > wrote in message
news:40******** @news.tm.net.my ...
public class StaticField2{
public static void main(String args[]){
private int x, y; // <<== error 1
for ( y = 0 ; y < 100 ; y++){
x = StaticMethod();
System.out.prin tln(" x = "+x);
}
}
public static int StaticMethod(){
private static int m = 0; // <<== error 2
m = m++;
return m;
}
}
why i can't declare x and y as a private?
why i cant declare m as private static?
New to Java(OOP?) world.
TIA.
--
"If we don't stand together than this is the end"
The Business