Suppose you have a class called Product that has the following instance variable
ID: 3711815 • Letter: S
Question
Suppose you have a class called Product that has the following instance variables defined:
private String prodID;
private String prodName;
private double prodPrice;
--The Product class has getters and setters defined for all the instance variables.
--Suppose there is a sub-class called Book that extends the Product class. In this class there is an instance variable called ISBN, of type String. This instance variable has a getter and a setter.
Write a setter method for the ISBN instance variable for the Book class , which will do two things: 1) set the ISBN instance variable and 2) set the ProdID of the Book object to be the same as that of its ISBN. Just write the setter method code, no need to submit the whole class.
Explanation / Answer
void setter()
{
string ISBN; //variable declaration
cout<<"Enter the ISBN number"<<endl;
cin>>ISBN; //accepting the value from the user
Product.prodID=ISBN; //storing ISBN to the prodID valriable
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.