need help in resolving the timeout program ran too long error"
package com.codegym.task.task06.task0603;
/*
Cat and Dog objects: 50,000 each
*/
public class Solution {
public static void main(String[] args) {
String cobjName ;
String dobjName ;
for(int i=1;i<=50000;i++){
cobjName = "cat" + i;
Cat objname = new Cat();
dobjName = "dog" + i;
Dog dobjname = new Dog();
cobjName = null;
dobjName = null;
}
}
}
class Cat {
@Override
protected void finalize() throws Throwable {
super.finalize();
System.out.println("Cat was destroyed");
}
}
class Dog {
@Override
protected void finalize() throws Throwable {
super.finalize();
System.out.println("Dog was destroyed");
}
}