Can we print a java message on console without using main method, static variable and static method?
问题 public class Test { /** * @param args */ // 1st way public static void main(String[] args) { // TODO Auto-generated method stub System.out.println("Test....!!!!!"); } // 2nd way static{ System.out.println("Test....!!!!!"); System.exit(1); } // 3rd way private static int i = m1(); public static int m1(){ System.out.println("Test...!!!!"); System.exit(0); return 0; } Other than this, can we print message any other way. 回答1: Of course you can, from a class constructor, method or instance block