Van.java 675 B

12345678910111213141516171819202122232425262728293031323334
  1. package J20250718.demo01_innerClass;
  2. /**
  3. * @author WanJl
  4. * @version 1.0
  5. * @title Van
  6. * @description
  7. * @create 2025/7/18
  8. */
  9. public class Van {
  10. String color;
  11. //创建内部类的对象
  12. private Engine engine=new Engine();
  13. private class Engine{
  14. String size;
  15. public void engineMethod(){
  16. System.out.println("内部类的方法.....");
  17. }
  18. }
  19. //外部类方法
  20. public void getEngineMethod(){
  21. //调用内部类的方法
  22. engine.engineMethod();
  23. }
  24. public void setEngineSize(String size){
  25. engine.size=size;
  26. }
  27. public String getEngineSize(){
  28. return engine.size;
  29. }
  30. }