DEV Community

hema latha
hema latha

Posted on

Cricket task

  1. Create a class called Cricket
  2. Have below method in it. public int calculate(int balls) { return balls * 6; }
  3. Create one more class called 'Player1'
  4. Have main method in it.
  5. Now, create instance for 'Cricket' class.
  6. Using instance, call calculate() method with 10 as argument.
  7. Now, store the returned result as score.
  8. print the score.

public class Cricket {

 public int calculate(int balls)
    {
   //System.out.println("gugan ball");
    return balls * 6; 
    }
Enter fullscreen mode Exit fullscreen mode

}

public class Player1 {
public static void main(String[] args) {
Cricket gugan = new Cricket();
int balls = gugan.calculate(10);

     System.out.println(balls);
}
Enter fullscreen mode Exit fullscreen mode

}

Top comments (0)