The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
March 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

why this error occurs ?

Posted by senthil on March 25, 2001 at 5:54 AM

class stat
{
int a=10;
static int a=10;
public static void main(String[] arrgs)
{
stat var=new stat();
System.out.println("Static variable a = " + a);
System.out.println("Instance variable a = " + a);
}
} // the output of this program is giving an error.
the problem here is when i give instance variable as b=10 instead of a=10; , there is no error,Why is this error occuring?
I wanna know y this error is occuring since the object is placed in the heap and the variables takes a memory place during runtime,and the variable of the static takes memory space during compilation..
Can any one explain me it in detail with an example?.




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us