1//You simply need to create an instance of the Object you created
2public Class Obj{
3 public void nonStaticMethod(){
4 //execute code
5 }
6 public static void main(string args[]){
7 Obj obj = new Obj();
8 obj.nonStaticMethod
9 }
10}
1// Static vs Object Called
2// Static Methods don't require you to call a constructor
3
4// Initialize statically
5public class MyClass {
6
7 private static int myInt;
8
9 static {
10 myInt = 1;
11 }
12
13 public static int getInt() {
14 return myInt;
15 }
16}
17
18// Then call it
19System.out.println(MyClass.getInt());
20
21// VS Constructor
22
23public class MyClass {
24
25 private int myInt;
26
27 public MyClass() {
28 myInt = 1;
29 }
30
31 public int getInt() {
32 return this.myInt;
33 }
34}
35// Then call it
36MyClass myObj = new MyClass();
37System.out.println(myObj.getInt());