Answer:
1) TurningDemo
public class TurningDemo
{ public static void main(String[] args)
{
Leaf obj1 = new Leaf();
Corner obj2= new Corner();
Page obj3= new Page();
Pancake obj4= new Pancake();
} }
2) ITurnable
public interface ITurnable
{
public void Turn();
}
3) Leaf class:
public class Leaf implements ITurnable
{
}
Page class:
public class Page implements ITurnable
{
}
Corner class:
public class Corner implements ITurnable
{
}
Pancake class:
public class Pancake implements ITurnable
{
}
Explanation:
The first is TurningDemo application which creates instance obj1, obj2, obj4 and obj4 of four classes Page, Corner, Pancake, and Leaf. new keyword is used to create new object or instance of each class.
The second is ITurnable interface. It contains a single method Turn() which is of type public.
Thirdly, classes named Page, Corner, Pancake, and Leaf implement ITurnable. implements keyword is used to implement a interface so this interface can be used by these classes.
These classes can also implement turn() of ITurnable interface as follows:
Leaf class:
public class Leaf implements ITurnable
{ public void turn()
{
}
}
Page class:
public class Page implements ITurnable
{
public void turn()
{
}
}
Corner class:
public class Corner implements ITurnable
{ public void turn()
{
}
}
Pancake class:
public class Pancake implements ITurnable
{ public void turn()
{
}
}