Untitled

Run Settings
LanguageJava
Language Version
Run Command
class Main { static int myStaticNumber = 0; int myNumber; /** * Constructor to init myNumber */ public Main(int myNumber){ this.myNumber = myNumber; } /** * static main method can access method(param) directly */ public static void main(String[] args) { int number = staticMethod(3); //Not that main cannot access instanceMethod() // because there is on object to operate on. // So to use it, we must create an object of Main Main main = new Main(3); //Now we can use instanceMethod() int otherNumber = main.instanceMethod(); System.out.println("Number 1:" + number + ", Number 2: " + otherNumber); } /** * Static here means that i have to invoke it * using * Main.staticMethod(param) * * note static method can't access myNumber * This is because it's not a static variable. * */ public static int staticMethod(int var){ return 7 * var; } /** * Instance method can access myNumber because it * works on the instance of the object. * * It can also invoke staticMethod * * It can also access static variables */ public int instanceMethod(){ return Main.staticMethod(myNumber); } }
Editor Settings
Theme
Key bindings
Full width
Lines