public class A {
static void print(){
int i=10;
System.out.println("i="+i);
}
void show(){
int j=20;
System.out.println("j= "+j);
}
public static void main(String[] args) {
int f=87;
A a =new A();
print();
a.show();
System.out.println(a.f); //compile error.
}
}
Can someone explain why i and j can be printed but f is giving compile error when i,j and f are local variables inside a method ? Thank you all for the initial replies.