DEV Community

Pavitra Aravind
Pavitra Aravind

Posted on

Today task

  1. Create a class called Cricket
  2. Create static variable int overs = 20;
  3. Create non-static variable int score;
  4. Have main method in it.
  5. Inside main method, create two instances dhoni, kohli.
  6. For dhoni, assign score as 50; dhoni.score = 50;
  7. For kohli, assign score as 60;
  8. Create a method (outside main method) as below. public void display() { System.out.println(score); System.out.println(overs); }
  9. Now, using object dhoni call display() method. dhoni.display()
  10. Using instance kohli, call display() method. kohli.display()

Input:

class cricket
{
static int overs = 20;
int score;

public static void main(String[] args)
{
cricket dhoni = new cricket();
dhoni.score = 50;

cricket kohli = new cricket();
kohli.score = 60;

kohli.display();

}
public void display()
{
System.out.println("kohli"+ score);
System.out.println("kohli"+ overs);
}

}

output:

Image description

Top comments (0)