使用创建对象传递新对象进行赋值
作者:互联网
package com_1;
public class Demo01 {
public static void main(String[] args) {
/*Person person = new Person();
Pig pig = new Pig();
person.eat(pig);*/
new Person().eat(new Pig());
}
}
class Person {
public void eat(Pig pig) {
System.out.println("我喜欢吃" + pig.name);
}
}
class Pig {
String name = "烤乳猪";
}
标签:public,创建对象,Pig,传递,Person,new,pig,class,赋值 来源: https://blog.csdn.net/weixin_45747908/article/details/122003097