• Non-static methods can use static and non-static variables • static methods can only use static variables. • static variable = class variable • Non-static variable = instance/object variables/attributes.
class static int variable1; public static void sayHelloAll(){ variable1 =0; variable2 =0; } int variable2; public void sayHello (){ variable1 =0; variable2 =0; }
Paradigm public class Student { String name; int finalGrade; public void sayHello(){ // print name } public void drawSomething(){ // draw } } public class MyProgram { public static void main(String [] arg) { Student john = new Student(); john.name = "John Doe"; john.sayHello(); jane.name = "Jane Doe"; jane.sayHello(); } } john jane
Methods • public void sayHello() { } • public void sayHello(String language) {} • public int giveMeANumber(){} • public int addThisNumbers(int x, int y) {}