We know that when writing each class, we need to test whether the class has errors. by writing a main () method in each class, we have a disadvantage, that is, the additional code that has been compiled must be carried with it. If this is troublesome for you, you can use Nested classes to place the test code.
/***** @ Author xiaanming **/public class innerclass {public void print (Object O) {system. out. println (O. tostring ();} public static class tester {public static void main (string [] ARGs) {innerclass minnerclass = new innerclass (); minnerclass. print ("xiaanming ");}}}
In this way, an independent class innerclass $ tester is generated (to run this program, execute Java innerclass $ tester and escape $ in Unix/Linux systems) you can use this class for testing, but you do not need to include it in your released product. before packaging the product, you can simply delete innerclass $ tester. class. In this way, you can test every class without any additional code in the packaged product. Is it very convenient? Haha