Question: 2- Consider the following program: public class Product { private int price ; public void setPrice(int theprice) { price = thePrice; } } public class
2- Consider the following program:
public class Product
{ private int price
; public void setPrice(int theprice)
{
price = thePrice; }
}
public class SpecialProduct extends Item
{ private int discount;
public void setDiscount(int theDiscount)
{ discount = theDiscount;
}}
public class Main{
public static void main(String[]args){
SpecialProduct product = new SpecialProduct();
}}
Which of the following compiles without a problem? Why?
a. product.discount = 20;
b. product.setDiscount(20);
c. product.setPrice(50);
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
