Task:
- Create a class Called PlayGround
- Create non-static variables as below. int score, balls, catches; String player_name;
- Create main method.
- Inside main method, create two instances as below. PlayGround player1 = new PlayGround("dhoni", 100, 3); PlayGround player2 = new PlayGround("jadeja", 56, 2, 30);
- Create appropriate constructors for handling above objects.
- Using player1 object, call batting() method. Print - score, player_name.
- Using player2 object, call allrounder() method. Print - score, player_name, balls, catches
public class PlayGround
{
int score,balls,catches;
String Player_name;
public PlayGround(String Player_name,int score,int catches)
{
this.score=score;
this.catches=catches;
this.Player_name=Player_name;
}
public PlayGround(String Player_name,int score,int catches,int balls)
{
this.score=score;
this.catches=catches;
this.balls=balls;
this.Player_name=Player_name;
}
public static void main(String[] args)
{
PlayGround Player1=new PlayGround("dhoni",100,3);
PlayGround Player2=new PlayGround("jadeja",56,2,30);
Player1.batting();
Player2.allrounder();
}
public void batting()
{
System.out.println(Player_name+" "+score+" "+catches);
}
public void allrounder()
{
System.out.println(Player_name +" "+score+" "+catches+" "+balls);
}
}
OUTPUT:
Top comments (0)