0
This program for Garbage Collection in Java is not working and showing error that"no public class found to execute"
class sample { String x; public Test(String x) { this.x=x; } static void show() { sample t1= newsample("t1"); display(); } static void display() { sample t2= new sample("t2"); } public static void main(String args[]) { show(); System.gc(); } @Override protected void finalize() throws Throwable { System.out.println(this.x+ " successfully garbage collected"); } }
5 odpowiedzi
0
The class with main() needs to be public. No keyword means that it's package private: only classes that are in same package can access it.
0
But it's still not working.Can you please send me the correct code.
0
Does this class have main() method?
0
yes
0
Save it in code playground and link it here.