0

Accessing static methods

Can we access static methods from another object after using destructor on the previously initialized object of that class?Does this help resolve the referrence from non-static context error? https://code.sololearn.com/cUMoSA5Tzu5z/?ref=app

16th Apr 2020, 5:35 PM
Arnold D'Souza
Arnold D'Souza - avatar
2 odpowiedzi
- 1
// how to solve non-static error public class Program { int i; public static void main(String[] args) { // System.out.println(i); //static error // way 1 var p = new Program(); System.out.println(p.i); // way 2 new Program().main2();} void main2(){ System.out.println(i); } }
16th Apr 2020, 6:34 PM
zemiak