0% found this document useful (0 votes)
204 views3 pages

Games

The document describes a package called "games" that contains two classes - Indoor and Outdoor. The Indoor class uses a default constructor while the Outdoor class uses a parameterized constructor. Both classes contain a display() method to print the game name and player name. The TestGames class creates objects of both classes and calls their display() methods to output the lists of indoor and outdoor games and players.

Uploaded by

Pulkit Agarwal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
204 views3 pages

Games

The document describes a package called "games" that contains two classes - Indoor and Outdoor. The Indoor class uses a default constructor while the Outdoor class uses a parameterized constructor. Both classes contain a display() method to print the game name and player name. The TestGames class creates objects of both classes and calls their display() methods to output the lists of indoor and outdoor games and players.

Uploaded by

Pulkit Agarwal
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Q10.

) Write a package for Games, which have two classes

Indoor and Outdoor. Use a function display () to generate the list of players for the specific games. Use default and parameterized constructors. Make use of protected access specifier. Also use finalize () method.
Indoor.java package games; public class Indoor { String gname; String pname; public Indoor() { gname="Carrom"; pname="Rahul"; } public void display() { System.out.println(""+gname); System.out.println(""+pname); } } Outdoor.java package games; public class Outdoor { String gnm; String pnm; public Outdoor(String s,String r) { gnm=s; pnm=r;

} public void display() { System.out.println(""+gnm); System.out.println(""+pnm); } } TestGames.java import games.*; class TestGames { public static void main(String args[]) { Indoor i=new Indoor(); System.out.println("List of Indoor Games and Players"); i.display(); Outdoor o=new Outdoor("Cricket","Rahul Dravid"); Outdoor o1=new Outdoor("Football","Roani"); System.out.println("List of Outdoor Games and Players"); o.display(); o1.display(); } }

Output :

You might also like