Originally posted by Cindy Glass:
The variable first holds a reference to an object. Then it is used to create riddle. The riddle variable also gets a reference to the same object in line c. Setting first to null does not get rid of the reference in riddle, which is held until the end of the method.
Originally posted by Roll:
<CODE><PRE>class A {
int a=1;
int b=2;
public int c=6;
public int d=3;
private int e=8;
private int f=8;
protected int g=10;
protected int h=11;
// this is your problem... class B is NOT an inner class of A
// } So I commented it out
class B {
int a1=c;
// int a2 =g;
// add the close of B then the close of A
}
// and close A
}
// get rid of this your referencing a non static variable from a static method... but that is another story
/*public static void main(String[] args) {
System.out.println(a);
} */
</CODE></PRE>
Compilation error:
B.java:15: Undefined variable: c
int a1=c;
Is it not possible to acces a public variable.
But as far as i know its said that public can be accessed inside or outside the class.Then,
Why iam getting a compilation errror.
Any suggestions or comments?