using c build a class named Candy and the subclasses Chocola
using c++ build a class named Candy and the subclasses Chocolate, Fruit, and Sour using inheritance. The name of the candy and the price are included in the Candy class. The child classes should all indicate how it tastes (chocolaty, fruity, and sour).
Solution
abstract class Candy
{
private:
double price;
String name;
public:
abstract void getTaste();
void setPrice(double p)
{
price=p;
}
void setName(String s)
{
name=s;
}
}
class Chocolate:public Candy
{
public:
String getTaste()
{
return \"chocolaty\";
}
}
class Fruit:public Candy
{
public:
String getTaste()
{
return \"Fruity\";
}
}
class Sour:public Candy
{
public:
String getTaste()
{
return \"sour\";
}
}

