public class ccc
{
    public ccc()
    {

        System.out.println("ccc");

}
/**
* @param args
*/
static
    {
System.out.println("static one is running");
}
 
public static void main(String[] args)
    {
// TODO Auto-generated method stub
System.out.println("main one is running");
A a = new A();
//a.main(args);
    
}
}
 
class A
{

static
    {
System.out.println("static is running");
}
 
public static void main(String[] args) {
System.out.println("main A is running");
}
 
public A() {
System.out.println("A is running");
}
}


/*
这说明静态的代码块是最优先运行的,然后是构造函数,而main函数是不会在不是选择入口main函数的时候主动运行的。
如需要调用的话那么必须显示执行a.main(args);
public 中,main函数先执行,其所在的类因为没有创建对象,构造函数不会调用
在创健对象时,该对象对应的类的静态函数先调用,然后是对象的构造函数,main函数不主动调用


*/

相关文章:

  • 2021-10-19
  • 2022-03-09
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
  • 2021-04-21
  • 2021-11-14
  • 2021-12-09
猜你喜欢
  • 2022-12-23
  • 2021-07-10
  • 2021-06-15
  • 2021-11-23
  • 2021-10-01
  • 2022-12-23
  • 2021-11-12
相关资源
相似解决方案