有一个班级,老师的数量最多10 人,学生的数量最多30 人
class level
{
private int teacher;
public level ( int teacher)
{
this . teacher = teacher;
}
public void num ( )
{
System. out. println ( "教师人数" + this . teacher) ;
}
class Engine
{
int student;
public Engine ( int student)
{
this . student = student;
}
public void num1 ( )
{
System. out. println ( "学生人数" + this . student) ;
}
}
public static void main ( String[ ] args)
{
level Level = new level ( 10 ) ;
Level. num ( ) ;
level. Engine engine = Level. new Engine ( 30 ) ;
engine. num1 ( ) ;
}
}
使用成员内部类来表示一辆轿车的品牌和发动机的最大马力以及最大扭规
class car
{
private String brand;
public car ( String brand)
{
this . brand = brand;
}
void word ( )
{
System. out. println ( "汽车品牌" + this . brand) ;
}
class Engine
{
String model;
public Engine ( String model)
{
this . model = model;
}
void word1 ( )
{
System. out. println ( "汽车品牌" + this . model) ;
}
}
public static void main ( String[ ] args)
{
car Car = new car ( "大众" ) ;
Car. word ( ) ;
car. Engine engine = Car. new Engine ( "Ea1230" ) ;
engine. word1 ( ) ;
}
}