-
-
Save anonymous/10dae6d740d07e024c0d517af0ac11e1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//******************************************************************* | |
// 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