文章列表
Havn't try java for severals months,I try to write a notepad to review something about Swing and IO.At first,I thought it's just a piece of cake,but lately I found it's not so easy,especially if I want to make it more functional.When open a text file,I found I can't read the Chinese,they are ...
java的初始化有成员初始化和构造器初始化,对于成员初始化,java尽力保证所有的变量在使用前都能得到恰当的初始化,对于局部变量,若未进行初始化,将以编译报错的形式来表现.对于类的数据成员:若不将其初始化,若类的字段为基本类型,会将其设置为默认值,若在类里定义一个对象引用时,则会设为null.
主要对构造器初始化进行分析
在类的内部,变量的定义会在任何方法(包括构造方法)被调用前得到初始化,静态数据只占用一份存储区域,静态变量的初始化要优先于非静态数据,若含有静态块,也会优先于非静态变量和非静态块.
例子如下
package com.fly;
public ...