为什么在Java中使用实例初始化块?

王林
王林 转载
2023-08-18 23:37:11 387浏览

为什么在Java中使用实例初始化块?

实时演示

public class Tester {
   public int a;
   { a = 10; }
   public static void main(String[] args) {
     System.out.println(new Tester().a);
   }  
}
It will print the value of an as 10.

以上就是为什么在Java中使用实例初始化块?的详细内容,更多请关注php中文网其它相关文章!

声明:本文转载于:tutorialspoint,如有侵犯,请联系admin@php.cn删除