DEV Community

Pavitra Aravind
Pavitra Aravind

Posted on

2

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

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay