Java内嵌类


<!-- /* Font Definitions */ @font-face {font-family:宋体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:黑体; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimHei; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:1 135135232 16 0 262144 0;} @font-face {font-family:"/@黑体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:1 135135232 16 0 262144 0;} @font-face {font-family:"/@宋体"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:12.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋体; mso-font-kerning:1.0pt;} h1 {mso-style-next:正文; margin-top:17.0pt; margin-right:0cm; margin-bottom:16.5pt; margin-left:21.25pt; text-align:justify; text-justify:inter-ideograph; text-indent:-21.25pt; line-height:240%; mso-pagination:lines-together; page-break-after:avoid; mso-outline-level:1; mso-list:l1 level1 lfo1; tab-stops:list 21.25pt; font-size:22.0pt; font-family:"Times New Roman"; mso-font-kerning:22.0pt;} h2 {mso-style-next:正文; margin-top:13.0pt; margin-right:0cm; margin-bottom:13.0pt; margin-left:1.0cm; text-align:justify; text-justify:inter-ideograph; text-indent:-1.0cm; line-height:173%; mso-pagination:lines-together; page-break-after:avoid; mso-outline-level:2; mso-list:l1 level2 lfo1; tab-stops:list 1.0cm; font-size:16.0pt; font-family:Arial; mso-fareast-font-family:黑体; mso-bidi-font-family:"Times New Roman"; mso-font-kerning:1.0pt;} h3 {mso-style-next:正文; margin-top:13.0pt; margin-right:0cm; margin-bottom:13.0pt; margin-left:0cm; text-align:justify; text-justify:inter-ideograph; line-height:173%; mso-pagination:lines-together; page-break-after:avoid; mso-outline-level:3; font-size:16.0pt; font-family:"Times New Roman"; mso-font-kerning:1.0pt;} p.4, li.4, div.4 {mso-style-name:"样式 标题 4"; mso-style-parent:"标题 3"; margin-top:13.0pt; margin-right:0cm; margin-bottom:13.0pt; margin-left:35.45pt; text-align:justify; text-justify:inter-ideograph; text-indent:-35.45pt; line-height:173%; mso-pagination:lines-together; page-break-after:avoid; mso-outline-level:3; mso-list:l1 level3 lfo1; tab-stops:list 35.45pt; font-size:15.0pt; mso-bidi-font-size:16.0pt; font-family:"Times New Roman"; mso-fareast-font-family:宋体; font-weight:bold;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} /* List Definitions */ @list l0 {mso-list-id:1147820946; mso-list-type:hybrid; mso-list-template-ids:-539340266 287331220 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;} @list l0:level1 {mso-level-tab-stop:18.0pt; mso-level-number-position:left; margin-left:18.0pt; text-indent:-18.0pt;} @list l1 {mso-list-id:1390962552; mso-list-template-ids:1939346452;} @list l1:level1 {mso-level-style-link:"标题 1"; mso-level-tab-stop:21.25pt; mso-level-number-position:left; margin-left:21.25pt; text-indent:-21.25pt;} @list l1:level2 {mso-level-style-link:"标题 2"; mso-level-text:"%1/.%2/."; mso-level-tab-stop:1.0cm; mso-level-number-position:left; margin-left:1.0cm; text-indent:-1.0cm;} @list l1:level3 {mso-level-style-link:"样式 标题 4"; mso-level-text:"%1/.%2/.%3/."; mso-level-tab-stop:35.45pt; mso-level-number-position:left; margin-left:35.45pt; text-indent:-35.45pt;} @list l1:level4 {mso-level-text:"%1/.%2/.%3/.%4/."; mso-level-tab-stop:42.55pt; mso-level-number-position:left; margin-left:42.55pt; text-indent:-42.55pt;} @list l1:level5 {mso-level-text:"%1/.%2/.%3/.%4/.%5/."; mso-level-tab-stop:49.6pt; mso-level-number-position:left; margin-left:49.6pt; text-indent:-49.6pt;} @list l1:level6 {mso-level-text:"%1/.%2/.%3/.%4/.%5/.%6/."; mso-level-tab-stop:2.0cm; mso-level-number-position:left; margin-left:2.0cm; text-indent:-2.0cm;} @list l1:level7 {mso-level-text:"%1/.%2/.%3/.%4/.%5/.%6/.%7/."; mso-level-tab-stop:63.8pt; mso-level-number-position:left; margin-left:63.8pt; text-indent:-63.8pt;} @list l1:level8 {mso-level-text:"%1/.%2/.%3/.%4/.%5/.%6/.%7/.%8/."; mso-level-tab-stop:70.9pt; mso-level-number-position:left; margin-left:70.9pt; text-indent:-70.9pt;} @list l1:level9 {mso-level-text:"%1/.%2/.%3/.%4/.%5/.%6/.%7/.%8/.%9/."; mso-level-tab-stop:77.95pt; mso-level-number-position:left; margin-left:77.95pt; text-indent:-77.95pt;} ol {margin-bottom:0cm;} ul {margin-bottom:0cm;} -->

1.1. 内嵌类

1.1.1. 代码

/*

  * To change this template, choose Tools | Templates

  * and open the template in the editor.

  */

 

package javatutorials;

 

/**

  *

  * @author wanpor

  */

public class InnerClass {

 

    public static void main(String[] args){

        // 创建静态内嵌类

        InnerClass.A ica = new InnerClass.A();

        ica.printInfo();

       

        // 创建非静态内嵌类

        InnerClass b = new InnerClass();

        InnerClass.B icb = b.new B();

        icb.printInfo();

    }

    // 静态内嵌类

    public static class A{

        static void printInfo(){

            System.out.println("A");

        }

    }

    // 非静态内嵌类

    public class B{

        void printInfo(){

            System.out.println("B");

        }

    }

}

 

1.1.2. 说明

1.       定义静态内嵌类;

2.       定义非静态内嵌类

3.       创建静态内嵌类对象

4.       创建非静态内嵌类对象

 


静态类不能实例化,类的成员都要是静态成员和静态方法,

非静态类一般需要实例化后才可以操作,不过接口和抽像类不能直接实例化。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值