有人可以给我这个代码的详细解释,并告诉我为什么它会打印出它打印的输出。这是我的测试的示例练习题。我真的不擅长这些方法和类部分。所以假设我对这个主题知之甚少。请逐行解释并告诉我值的变化。因此,如果测试中出现类似的问题,我将能够做到。输出为apples,grapes,pears,kiwi,oranges,pears,pears,grapes,oranges,20
public Purchase questionSampleInClass(Purchase p1, int newX) {
newX=30
Purchase p2= new Purchase("banana", 5, 4.50, 12);
Purchase p3= new Purchase("plum", 6, 5.50, 10);
p1=p2;
p3=this;
p3.setName("pears");
p1.setName("oranges");
p1 = new Purchase("kiwi", 6, 3.00, 3);
System.out.println(this.getName());
System.out.println(p2.getName());
System.out.println(p3..getName());
return p2;
}
public class PurhaseDemoClassProblem {
public static void main(String{} args) {
Purchase oneSale= new Purchase("apples", 4, 3.50, 6);
Purchase twoSale= new Purchase("grapes", 8, 1.99, 4);
Purchase threeSale;
int x=20;
System.out.println(oneSale.getName());
Syste,.out.println(twoSale.getName());
threeSale= oneSale.questionSampleInClass(twoSale, x);
System.out.println(oneSale.getName());
System.out.println(twoSale.getName());
System.out.println(threeSale.getName());
System.out.println(x);
}
}