Earlier in this book I suggested putting a main( ) in every class to act as a test bed for that class. One drawback to this is the amount of extra compiled code you must carry around. If this is a problem, you can use a nested class to hold your test code: Feedback
//: c08:TestBed.java // Putting test code in a nested class. public class TestBed { public TestBed() {} public void f() { System.out.println("f()"); } public static class Tester { public static void main(String[] args) { TestBed t = new TestBed(); t.f(); } } } ///:~
This generates a separate class called TestBed$Tester (to run the program, you say java TestBed$Tester). You can use this class for testing, but you don’t need to include it in your shipping product; you can simply delete TestBed$Tester.class before packaging things up.
=================================================================================
Compile result :
E:/MyDoc/Exercises のディレクトリ
2006/03/23 09:37 358 TestBed$Tester.class
2006/03/23 09:37 439 TestBed.class
2006/03/23 09:37 242 TestBed.java
3 個のファイル 1,039 バイト
0 個のディレクトリ 15,933,108,224 バイトの空き領域