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.
创建非静态内嵌类对象
静态类不能实例化,类的成员都要是静态成员和静态方法,
非静态类一般需要实例化后才可以操作,不过接口和抽像类不能直接实例化。