Liskov Substitution Principal (LSP) is violated.
LSP says that the object of a derived class should be able to replace an object of the base class without bringing any error in the system or modifying the behavior of the base class.
So as to the principle we should be able to replace a Bear object by any object of Grizzy ,Teddy or Chicago without bringing any error.
As per polymorphism rule all the derived class may define its own function definition for the function eat(), so it can produce an error if we want to do the replacement of the Bear object by any Derived class object.
so it can be fixed by using an interface to have the function declaration eat() , like
interface eating {
void eat(Food);
}
now each derived class can implement this interface defining its own definition for that function eat().
class Teddy : eating
{
void eat(Food)
{
//
}
}
class Grizzy : eating
{
void eat(Food)
{
//
}
}
class Chicago : eating
{
void eat(Food)
{
//
}
}
OR
we may define the base class Bear as an abstract class as it is not defining the function eat() and it will prevent the object creation of the class Bear ,declare the function eat() as an abstract also, like
abstract class Bear
{//
abstract void eat(Food);
}
For questions 1-5, each block of pseudocode violates 1 of the S SOLID principles. Without repeating...