The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
November 2000



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.


Static Variables

Posted by Rakesh.S on November 22, 2000 at 4:11 AM

In the following piece of code

Class Base{
int i;


public static void main(String arr[]){
int y = 0;
Base b = new Base();
y = b.i;//Gives an error saying that a static function cannot refer a non-static variable.

But why does the statement Base b =new Base() doesn't give error eventhough the constructor Base() is not static.

  • Reply Elangovan November 22, 2000 at 6:24 AM (0)

Sponsored Links

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