郁闷了,这是我基础测试里的题。代码如下 
- public class text8 {
 
 -         public static void main(String[] args) {
 
 -                 outer oer=new outer();//创建对象
 
 -                 oer.outMethod(8);
 
  
-         }
 
  
- }
 
 - class outer{
 
 -         private int x=100;
 
 -         
 
 -         private void outMethod2(int a)//外部类方法
 
 -                 {
 
 -                         System.out.println(a+"   outMethod2");
 
 -                 }
 
 -         
 
 -         void outMethod(int x)
 
 -                 {          inner inn=new inner();        //创建内部类对象
 
 -                         inn.inMethod(45);                //调用内部类函数
 
 -                         System.out.println(x+"   outMethod");
 
 -                 }
 
 -         //内部类
 
 -         class inner{
 
 -                 
 
 -                 void inMethod(int a)//内部类方法
 
 -                         {          int y=a+x;                        //访问外部类中的x
 
 -                                 outMethod2(6);                //调用外部类函数
 
 -                                 System.out.println(y+"   inMethod");
 
 -                         }
 
 -         }
 
 - }
 
 
  复制代码 |