参考:https://zhidao.baidu.com/question/1433773942389340379.htmlhtml
//--------------------------------------------------------------------------------测试
package test;spa
public class B {
B() {
System.out.println("B构造块3"); //3. 本身的构造方法
}
static {
System.out.println("B静态块1"); //1.本身的静态方法
}
{
System.out.println("B非静态块2"); //2. 本身的非静态块
}
public void testB(){
System.out.println("我是B类的特有方法");
}
}
htm
//--------------------------------------------------------------io
package test;class
public class A {
A(){
System.out.println("我是A类的构造无参方法");
}
static {
System.out.println("A静态块");
}
{
System.out.println("A非静态块");
}
//在A中的方法 调用 B的方法
public void testA(){
B b = new B();
b.testB();
}
//私有
@SuppressWarnings("unused")
private void testPrivateA(){
System.out.println("我是A类private特有方法");
}
}
test
这个结果稍微复杂点基础