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"); } }

6th Jun 2018, 4:06 PM
harshit
harshit - avatar
5 ответов
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.
6th Jun 2018, 4:09 PM
BlazingMagpie
BlazingMagpie - avatar
0
But it's still not working.Can you please send me the correct code.
6th Jun 2018, 5:08 PM
harshit
harshit - avatar
0
Does this class have main() method?
6th Jun 2018, 6:27 PM
BlazingMagpie
BlazingMagpie - avatar
0
yes
6th Jun 2018, 6:28 PM
harshit
harshit - avatar
0
Save it in code playground and link it here.
6th Jun 2018, 7:07 PM
BlazingMagpie
BlazingMagpie - avatar