day07-匿名对象的说明

This commit is contained in:
2026-07-21 10:41:16 +08:00
parent 7acffc1b68
commit 6cd6611b37
@@ -0,0 +1,18 @@
package com.inmind.scanner01;
import java.util.Scanner;
/*
匿名对象:没有名字的对象
匿名对象的使用场景:当一个对象只要被使用一次,可以使用匿名对象来简单实现
*/
public class Demo04 {
public static void main(String[] args) {
//只接收一个整数
/*Scanner sc = new Scanner(System.in);
int i = sc.nextInt();*/
int i = new Scanner(System.in).nextInt();
System.out.println(i);
}
}