
write a package for games which have two classes indoor and outdoor.use a function display() to generate a list of players for the specific games.use default and parameterised constructor. make use of protected access specifier and also use the finalize() method

We have created a package named games where we have defined two classes Indoor and Outdoor. In the main class, we have imported this package and using a function display(), we have generated a list of players for the specific games.
1)Indoor.java
package Games;
public class Indoor
{
protected String player;
public Indoor()
{
}
public Indoor(String p)
{
player = p;
}
public void display()
{
System.out.println(player);
}
protected void finalize()
{
System.out.println("Terminating Indoor...");
}
}
2)Outdoor.java:
package Games;
public class Indoor
{
protected String player;
public Indoor()
{
}
public Indoor(String p)
{
player = p;
}
public void display()
{
System.out.println(player);
}
protected void finalize()
{
System.out.println("Terminating Indoor...");
}
}
3)Players.java
import Games.*;
class Players
{
public static void main(String args[])
{
Indoor In[] = new Indoor[4];
In[0] = new Indoor("A");
In[1] = new Indoor("B");
In[2] = new Indoor("C");
In[3] = new Indoor("D");
System.out.println("Indoor Players...");
for(int i=0;i<In.length;i++){
In[i].display();
}
System.out.println("Outdoor Players...");
Outdoor Out[] = new Outdoor[4];
Out[0] = new Outdoor("E");
Out[1] = new Outdoor("F");
Out[2] = new Outdoor("G");
Out[3] = new Outdoor("H");
for(int i=0;i<Out.length;i++){
Out[i].display();
}
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.