[Java daily question] 20161207, java20161207
Package Dec2016; public class Ques1207 {public static void main (String [] args) {new Test (); new Test (1); new Test ("1"); System. out. println ("number of instances:" + Test. getNumOfInstances () ;}} class Test {private static int numOfInstances = 0; // records the number of instances {numOfInstances ++; // constructs a code block, calculate the number of instances} public Test () {} public Test (int num) {} public Test (String str) {this (); // call the no-argument constructor} // return the number of created instances. public static int getNumOfInstances () {return numOfInstances ;}}
Today's question:
Can the main program properly run and output results? (Click "[Java daily question] 20161207" below to view issue resolution 20161206)
Questions originally published on the public account and short book: [Java daily question] 20161207, [Java daily question] 20161207