1、类的成员:初始化块(代码块)
初始化块(代码块)也是类的第四个成员(属性,方法,构造器)。
1、代码块如果有修饰的话,那么只能使用static。
2、分类:静态代码块,非静态代码块
class Order {
private int orderId;
private String orderName;
//初始化块(代码块)
{
orderId = 1002;
orderName = "AA";
System.out.println("我是非静态代码块1");
}
{
System.out.println("我是非静态代码块2");
}
public Order() {
super();
// TODO Auto-generated constructor stub
}
public Order(int orderId, String orderName) {
super();
this.orderId = orderId;
this.orderName = orderName;
}
public int getOrderId() {
return orderId;
}
public void setOrderId(int orderId) {
this.orderId = orderId;
}
public String getOrderName() {
return orderName;
}
public void setOrderName(String orderName) {
this.orderName = orderName;
}
}