Home > Java > javaTutorial > Cricket task

Cricket task

Mary-Kate Olsen
Release: 2025-01-02 14:19:39
Original
165 people have browsed it

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; 
    }
Copy after login

}

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

     System.out.println(balls);
}
Copy after login

}

The above is the detailed content of Cricket task. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template