A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 地狱天堂 中级黑马   /  2014-8-27 15:06  /  993 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 地狱天堂 于 2014-8-27 18:24 编辑
  1. public class TestEveryDay {
  2.         public static void main(String[] args) {
  3.                 //创建内部类对象
  4.                 Out.In in=new Out().new In();
  5.                 in.run();
  6.                 System.out.println();
  7.                
  8.                 //创建静态内部类对象
  9.                 Out.StaticIn in2=new Out.StaticIn();
  10.                 in2.staticRun();
  11.                 System.out.println();
  12.                
  13.                 //使用静态内部类的静态方法
  14.                 StaticIn.staticRun2();
  15.         
  16.         }
  17. }
  18. //外部类
  19. class Out{
  20.         int x=1;
  21.         //内部类
  22.         class In{
  23.                 int x=2;
  24.                 public void run(){
  25.                         int x=3;
  26.                         System.out.println("外部类x="+new Out().x+",内部类x="+this.x+",方法中的x="+x);
  27.                 }
  28.         }
  29.         
  30.         //静态内部类
  31.         static class StaticIn{
  32.                 int x=4;
  33.                 public void staticRun(){
  34.                         int x=5;
  35.                         System.out.println("外部类x="+new Out().x+",静态内部类x="+this.x+",方法中的x="+x);
  36.                 }
  37.                 public static void staticRun2(){
  38.                         System.out.println("内部静态方法");
  39.                 }
  40.         }
  41. }
复制代码
复习内部类,写个程序自己理下思路

1 个回复

倒序浏览
小手一抖{:3_64:} 金币到手
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马