The title says it all.
I have a unique color in every derived class and it is declared static.
Its like this:
class CandyBlue extends Candy
{
public static final String color = "blue";
}
class CandyRed extends Candy
{
public static final String color = "red";
}
then i have an object S of type Candy
class CandyFrenzy
{
Candy candies[][];
public CandyFrenzy()
{
candies = new Candy[4][4];
candies[0][0] = new CandyBlue();
candies[0][1] = new CandyRed();
....
}
public static void main(String args[])
{
CandyFrenzy candyFrenzy = new CandyFrenzy();
Candy candy;
for(int a=0; a<4; a++)
{
for(int b=0; b<4; b++)
{
candy = candies[a][b];
//print the color of the candy;
}
}
}
}
The Candy
class dont have a member color, so i dont need to post it. The only importance of the Candy class is for polymorphism purposes.
The code above is not tried, so if im not sure if it runs accordingly.
How can i print the color of the candy?