匿名对象:没有变量名的对象
格式:
数据类型 变量名 = new 数据类型(参数列表);// 有名对象
new 数据类型(参数列表);
举例:
public class AnonymousDemo {
public static void main(String[] args) {
// 传统的写法
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
// 匿名对象的方式
int num02 = new Scanner(System.in).nextInt();
int num03 = new Scanner(System.in).nextInt();
Sysstem.out.println(num02);
// 开发中 使用匿名对象进行参数的传递
checkInput(new Scanner(System.in));
原文:https://www.cnblogs.com/zlh109/p/14003687.html