public class interclassDemo {
public static void main(String[] args) {
Outerclass p1=new Outerclass(); //创建外部类
p1.tell1(); //调用外部类的方法
Outerclass.Interclass p2=p1.new Interclass(); //创建内部类的格式
p2.tell2(); //调用内部类的方法
p2.show();
}
}
class Outerclass{ //定义外部类
private int i=10;
void tell1(){
System.out.println("外部类方法");
}
void show1(){
System.out.println("内部类调用了我");
}
class Interclass{
private int a=100;
void tell2(){
System.out.println("内部类方法");
}
void show(){ //创建函数调用外部类方法
show1();
}
}
}
public static void main(String[] args) {
Outerclass p1=new Outerclass(); //创建外部类
p1.tell1(); //调用外部类的方法
Outerclass.Interclass p2=p1.new Interclass(); //创建内部类的格式
p2.tell2(); //调用内部类的方法
p2.show();
}
}
class Outerclass{ //定义外部类
private int i=10;
void tell1(){
System.out.println("外部类方法");
}
void show1(){
System.out.println("内部类调用了我");
}
class Interclass{
private int a=100;
void tell2(){
System.out.println("内部类方法");
}
void show(){ //创建函数调用外部类方法
show1();
}
}
}