code
package javahomework; import javax.swing.JOptionPane; class TestC { static int count = 0; public static TestC getInstance() { TestC x = new TestC(); count++; return x; } public static String get_count() { return String.valueOf(count); } } public class HW11 { public static void main(String args[]) { TestC c1 = TestC.getInstance(); TestC c2 = TestC.getInstance(); TestC c3 = TestC.getInstance(); JOptionPane.showMessageDialog(null, TestC.get_count()); } }
沒有留言:
張貼留言