Logo

dev-resources.site

for different kinds of informations.

Cricket task

Published at
12/31/2024
Categories
java
programming
Author
hema latha
Categories
2 categories in total
java
open
programming
open
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; 
    }

}

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

     System.out.println(balls);
}

}

Featured ones: