package csdn;
public class Employee
{
public static String company="china soft";
private String name;
private String phone="0755-51595599";
//代码块
{
System.out.println("Non-Static Block"+name);
System.out.println("Employee phone"+phone);
}
// //静态代码块
static{
System.out.println("Static Block");
// System.out.println(name);非静态的代码还没进入内存无法读取。
System.out.println("Employee Company:"+company);
}
//默认构造函数
public Employee()
{
this("Unknown");
// 这里打印不出来
System.out.println("ssssssssssEmployee()"+name);
System.out.println("ssssssssssEmployee()"+name);
System.out.println("ssssssssssEmployee()"+name);
System.out.println("ssssssssssEmployee()"+name);
}
public Employee(String name)
{
System.out.println("Employee(String)");
this.name=name;
}
public static void main(String args[])
{
new Employee();
}
}
package csdn;
public class Manager extends Employee
{
public static String department="sale";
private int salary=8000;
String name;
static//静态代码块
{
System.out.println("Sub Static Block");
System.out.println("Manger department: "+department);
}
//代码块
{
System.out.println("Sub Non-Static Block");
System.out.println("Manger department: "+salary);
}
//默认构造函数
public Manager()
{
this("Test");
System.out.println("Manager()"+name);
}
public Manager(String name)
{
super("Unknown");
this.name=name;
System.out.println("Manager(String)");
}
public static void main(String args[])
{
new Manager();
}
}
|
|