Skip to content

Instantly share code, notes, and snippets.

Created February 17, 2017 17:24
Show Gist options
  • Save anonymous/10dae6d740d07e024c0d517af0ac11e1 to your computer and use it in GitHub Desktop.
Save anonymous/10dae6d740d07e024c0d517af0ac11e1 to your computer and use it in GitHub Desktop.
//*******************************************************************
// Edited with https://www.compilejava.net/
// Static member example
//*******************************************************************
import java.lang.Math; // headers MUST be above the first class
// one class needs to have a main() method
public class HelloWorld
{
// arguments are passed using the text field below this editor
public static void main(String[] args)
{
OtherClass myObject = new OtherClass();
System.out.println(myObject);
myObject.readCount();
OtherClass obj2 = new OtherClass();
obj2.readCount();
myObject.readCount();
}
}
// you can add other public classes to this editor in any order
public class OtherClass
{
private static int count; // gets 0 here automatically, but not if this was a local var of a method
public OtherClass(){
count++;
}
public void readCount(){
System.out.println(count);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment