package com.samsung.java;
public class TestInnerClass {
public static void main(String[] args) {
//创建一个静态的成员内部类对象
Animal.Dog dog = new Animal.Dog(5.0);
//创建一个非静态的成员内部类对象
Animal animal = new Animal("八哥", 2);
Animal.Bird bird = animal.new Bird("red");
}
}
class Animal {
String name;
int age;
public Animal(String name, int age) {
super();
this.name = name;
this.age = age;
}
//非静态的成员内部类
class Bird {
String color;
public Bird(String color) {
super();
this.color = color;
}
}
//静态的成员内部类
static class Dog {
double weight;
public Dog(double weight) {
super();
this.weight = weight;
}
}
}
如何创建成员内部类
最新推荐文章于 2023-03-23 08:00:00 发布