day(9)The Inner Class

One class only in a project,but we still need redefine a class in a defined class

reason:
We wish to encapsulate a function which we don't want it exposed to the outside
And then manage this function or data uniformly.


public class MyClass{
    //The car exists first,then the engine
    Car bz= new Car();
    //We rarely use this way.
    Car.Engine engine = bz.new Engine();
    //Invoking the static inner class
    //We use this more.
    Car.Color color = new Color();
}

The inner class is the member of the external class
It can access the memers of the external class,but vice versa(反之亦然)
It can use the modifiers : public,private,protected,final,but the outer class can only
use public
It can be common inner class(use object to invoke the members),or static inner class(use class name to invoke the static members.

public class Car{
//compared with the inner class explaining the status of it.
  private int wheels;

private void start(){
     wheels = 4;
      // use the inner class inside
      Engine engine = new Engine();
    }

      public static class Color{
          private String color;
}
      public class Engine{
          public int a;
       public engine(){
          wheels = 5;
          start();
     }
  }
}
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • pyspark.sql模块 模块上下文 Spark SQL和DataFrames的重要类: pyspark.sql...
    mpro阅读 13,216评论 0 13
  • The Great A.I. Awakening How Google used artificial intel...
    图羽阅读 5,179评论 0 3
  • 感恩女儿转眼间已经长大,我们要回老家,她却坚决不回,认为这是她自己独处的最好时候。这几天独自留下,一个人吃饭,一个...
    武丹yoyo阅读 1,261评论 0 0
  • 昨天上午参加读书会,大家读的是<<坚毅>>这本书,书里面作者说:当她辞掉令人艳羡的工作去做一名老师的时候,她才发现...
    王五月阅读 3,793评论 0 2
  • 刘双鹤,焦点解决讲师一期班,平顶山,成长分享第686天(2017.11.20星期一) 帮助探索想法的开放式提问(复...
    在路上_1阅读 1,355评论 0 0

友情链接更多精彩内容