1、this关键字
public class Example10 {
public Example10(){
System.out.println(" 构造方法一被调用了");
}
public Example10(int x){
this();
System.out.println(" 构造方法二被调用了");
}
public Example10(boolean b){
this(1);
System.out.println(" 构造方法三被调用了");
}
public static void main(String[] args) {
Example10 test =new Example10(true);
}
}
2、内部类
public class Example11 {
public String name="Outer";
private class Inner{
String name="inner";
void showName(){
System.out.println(name);
}
}
public static void main(String [] arges){
Inner inner=new Example11().new Inner();
inner.showName();
}
}
class Father{
private String name="zhangjun";
class Child{
void introFather(){
System.out.println("我爸爸的名字叫:"+name);
}
}
}
public class Example12 {
public static void main(String[] args) {
Father.Child c=new Father().new Child();
c.introFather();
}
}
运行结果: