0% found this document useful (0 votes)
5 views

Assignment 7

The document defines classes for different types of players that inherit from a base Player class. It defines CricketPlayer, FootballPlayer, and HockeyPlayer classes that each extend the Player class and include additional details like team, club, or country. The main method creates objects of each player type by getting input and calling their displayDetails methods to output the player details.

Uploaded by

aishwarya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Assignment 7

The document defines classes for different types of players that inherit from a base Player class. It defines CricketPlayer, FootballPlayer, and HockeyPlayer classes that each extend the Player class and include additional details like team, club, or country. The main method creates objects of each player type by getting input and calling their displayDetails methods to output the player details.

Uploaded by

aishwarya
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

NAME – vaishnavi Vijay Mahajan Roll No.

: 33 FYMCA-B

// Player class

import java.util.Scanner;

class Player {

private String name;

private int age;

public Player(String name, int age) {

this.name = name;

this.age = age;

public void displayDetails() {

System.out.println("Name: " + name);

System.out.println("Age: " + age);

// CricketPlayer class inheriting from Player


class CricketPlayer extends Player {

private String team;

public CricketPlayer(String name, int age, String team) {

super(name, age);

this.team = team;

public void displayDetails() {

super.displayDetails();

System.out.println("Team: " + team);

// FootballPlayer class inheriting from Player

class FootballPlayer extends Player {

private String club;

public FootballPlayer(String name, int age, String club) {

super(name, age);

this.club = club;
}

public void displayDetails() {

super.displayDetails();

System.out.println("Club: " + club);

// HockeyPlayer class inheriting from Player

class HockeyPlayer extends Player {

private String country;

public HockeyPlayer(String name, int age, String country) {

super(name, age);

this.country = country;

public void displayDetails() {

super.displayDetails();

System.out.println("Country: " + country);

}
}

// Main class

public class Main {

public static void main(String args []) {

Scanner sc = new Scanner(System.in);

String name, country, name2,name1,country1,country2;

int age ,age2,age1;

// Create objects of each player type

System.out.println("Enter Name, Agw, Country");

name = sc.next();

age = sc.nextInt();

country = sc.next();

CricketPlayer cricketPlayer = new CricketPlayer(name, age, country);

System.out.println("Cricket Player Details:");

cricketPlayer.displayDetails();

name1 = sc.next();
age1 = sc.nextInt();

country1 = sc.next();

FootballPlayer footballPlayer = new FootballPlayer(name1, age1,


country1);

System.out.println("\nFootball Player Details:");

footballPlayer.displayDetails();

// Display player details

name2 = sc.next();

age2 = sc.nextInt();

country2 = sc.next();

HockeyPlayer hockeyPlayer = new HockeyPlayer(name2, age2,


country2);
System.out.println("\nHockey Player Details:");

hockeyPlayer.displayDetails();

Output

You might also like