package com.example.demo.controller; import com.example.demo.tool.Cat; import com.example.demo.tool.RagdollCat; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("/") public class ClassController { @GetMapping("/class") public void classDemo(){ //对象就是类的实例化 Cat tangguo = new Cat(); String catName1 = tangguo.formatName(); System.out.print(catName1); System.out.print("\r\n"); tangguo.setAge(3); //私有变量通过方法赋值 tangguo.name = "糖果"; //公开变量可以直接赋值 String catName = tangguo.formatName(); System.out.print(catName); System.out.print("\r\n"); tangguo.printAge(); } @GetMapping("/extends") public void extendsDemo(){ RagdollCat ragdollCat = new RagdollCat(); ragdollCat.name = "小布"; ragdollCat.say(); String catName = ragdollCat.formatName(); System.out.print(catName); System.out.print("\r\n"); System.out.print } }