I am having issues understanding what exactly polymorhism is and how it differs from inheritance. I have researched the web and found many answers that gives very technical deffinitions on what polymorphism is but nothing in which i really understand too well. I have come up with an example that might be polymorphism but may not be.
MY example:
Say you have a Gym with many levels of membership.
- basic member
- silver member
- gold member
and each class is a basic member but has more function
class basicMember(){
private double rate = 10;
privatedbl poolPrice = 5;
public void setRate (dbl in);
{
rate = in;
}
public dbl getRate()
{
return rate;
}
public dbl getPoolPrice()
{
return poolPrice;
}
}
class silverMember extends basicRate()
{
private dbl poolPriceDis = .9;
setRate(15);
public dbl getPoolPriceDis(){
return getPoolPrice() * poolPriceDis;
}
}
class goldMember extends basicRate(){
private dbl poolPriceDis = .85;
setRate(20);
public dbl getPoolPriceDis(){
return getPoolPrice() * poolPriceDis;
}
}
Would this be an example of inheritance or polymorphism or both? Please explain.....