歡迎使用CSDN-markdown編輯器

淺談靜態代碼塊與非靜態代碼塊的理解和解釋
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”);
}

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章