- 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
package terminaltask;
public class Playground {
int score, balls, catches;
String player_name;
public Playground(String player_name, int score)
{
this.player_name = player_name;
this.score= score;
}
public Playground(String player_name,int score,int catches,int balls)
{
this.player_name = player_name;
this.score = score;
this.catches =catches;
this.balls =balls;
}
public static void main(String[] args)
{
// TODO Auto-generated method stub
Playground player1 = new Playground("dhoni",100);
Playground player2 = new Playground("jadeja",56,2,30);
player1.batting();
player2.alrounder();
}
public void batting()
{
System.out.println(player_name+score);
}
public void alrounder() {
System.out.println(player_name+score+balls+catches);
}
}
out put
dhoni100
jadeja56302
Top comments (0)