淺談靜態代碼塊與非靜態代碼塊的理解和解釋
public class HelloB extends HelloA{
int s;
String m;
// public HelloB() {
// System.out.println(“HelloB”);
//
// }
{
System.out.println("I'm B class");
}
// public HelloB() {
// // super();
// System.out.println("HelloB");
// }
public HelloB() {
System.out.println("HelloB");
}
public HelloB(int s, String m) {
// super();
this.s = s;
this.m = m;
// System.out.println(“gggg”);
}
static {
System.out.println("static B");
}
public static void main(String[] args) {
new HelloB();
}
}
package com.abc.edu.cn;
public class HelloA {
int age;
String name;
public HelloA (){
System.out.println(“HelloA”);
}
public HelloA(int age, String name) {
super();
this.age = age;
this.name = name;
}
{
System.out.println(“I’m A class”);
}
static {
System.out.println(“static A”);
}
}