Question: Tracing private String name; private int price; public Product(String n, int p) { name = n; price = p; } public String toString() { return

Tracing private String name;

private int price;

public Product(String n, int p) { name = n; price = p; } public String toString() { return name + " price: " + price; } public int getPrice(){return price; } public void discount(int sale){ price = price - sale; }

}

public class TracingQuiz1 {

public static void main(String[] args) { Product phone1 = new Product("iphone12", 4000); Product h2 = new Product("airpods", 300); int s1 = 50; System.out.println(h2); h2.discount(s1); System.out.println(h2); phone1.discount(h2.getPrice() + 20 ); System.out.println(phone1); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!