Limited access

Upgrade to access all content for this subject

Consider the following classes.

public class Animal 
{
    // instance variables, constructor, 
    // and other methods not shown.

    public String getSpecies()
    {
        // code not shown
    }

    public void consumeFood(Food diet)
    {
        // code not shown
    }

    public int getAge()
    {
        // code not shown
    }
}

public class Food 
{
    // variables, constructors, and methods not shown
}

public class Pig extends Animal
{
    // variables, constructors, and other methods not shown

    public int countPiglets(Pig[] piglets)
    {
        // code not shown
    }
}

A Pig consumes food in a different manner than other animals.

What would be the BEST approach to take to define this difference?

A

Define the following method in the Animal class:

public void consumePigFood(Food diet)
{
    // code not shown
}
B

Modify the following method in the Animal class:

public void consumeFood(Food diet)
{
    // code not shown
}
C

Define the following method in the Pig class:

public Food consumeFood(Food diet)
{
    // code not shown
}
D

Define the following method in the Pig class:

public void consumePigFood(Food diet)
{
    // code not shown
}
E

Define the following method in the Pig class:

public void consumeFood(Food diet)
{
    // code not shown
}
Select an assignment template