I have read from a website that instance variables can be accessed directly within the class but my code below works only with object. can someone please help.Thanks in advance!
public class InstanceVariable
{
int instVariable;
// Instance variable are accessed through objects
public static void main(String []args)
{
/* Local variables has no default value but Instance variables
can have default value */
int a = 10;
// Here local variables a cannot have access modifiers
InstanceVariable obj = new InstanceVariable();
System.out.println(obj.instVariable);
System.out.println(a);
}
}