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

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!