12345678910111213141516171819202122232425262728293031 |
- package J20250718.demo01_innerClass;
- /**
- * @author WanJl
- * @version 1.0
- * @title TestUserDao
- * @description
- * @create 2025/7/18
- */
- public class TestUserDao {
- public void method(){
- //这个匿名内部类的生命周期,就是从这开始-----
- UserDao userDao=new UserDao() {
- @Override
- public void addUser() {
- System.out.println("匿名内部类.....");
- }
- };
- userDao.addUser();
- //----到这结束------
- }
- public static void main(String[] args) {
- TestUserDao testUserDao = new TestUserDao();
- testUserDao.method(); //调用方法,方法中就创建一个匿名内部类
- }
- }
|