Giter Site home page Giter Site logo

javalearn's Introduction

记录java学习过程


内部类的主要作用如下:

  • 内部类提供了更好的封装,可以把内部类隐藏在外部类之内,不允许同一个包中的其他类访问该类
  • 内部类的方法可以直接访问外部类的所有数据,包括私有数据
  • 内部类所实现的功能使用外部类同样可以实现

  • Inner类可以使用任意访问控制符,如public、protected、private等

  • 定义了成员内部类后,必须使用外部类对象来创建内部类对象,而不能直接去new一个内部类对象

  • 外部类是不能直接使用内部类成员和方法

  • 如果外部类和内部类具有相同的成员变量和方法,内部类默认访问自己的成员变量和方法

    Hero garen=new Hero(); Inner i = garen.new.Inner()

静态内部类不能直接访问外部类的非静态成员,但可以通过new 外部类().成员的方式访问;

访问外部类非静态类 new OuCla().a
访问外部类静态 OuCla.b
访问外部类中的同名静态属性 Infro15.classWind
访问外部类中的异名静态属性 classGrass

方法内部类


必须调用才会执行

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.