12345678910111213141516171819202122232425262728293031323334 |
- package J20250718.demo01_innerClass;
- /**
- * @author WanJl
- * @version 1.0
- * @title Van
- * @description
- * @create 2025/7/18
- */
- public class Van {
- String color;
- //创建内部类的对象
- private Engine engine=new Engine();
- private class Engine{
- String size;
- public void engineMethod(){
- System.out.println("内部类的方法.....");
- }
- }
- //外部类方法
- public void getEngineMethod(){
- //调用内部类的方法
- engine.engineMethod();
- }
- public void setEngineSize(String size){
- engine.size=size;
- }
- public String getEngineSize(){
- return engine.size;
- }
- }
|