Please tell me the solution of this program.

/* Count the number of cats
Write a code that counts the number of cats created (count) and then displays it on the screen.

public class Solution
    public static void main(String[] args)
        Cat cat1 = new Cat();
        //add your code here

        Cat cat2 = new Cat();
        //add your code here

        System.out.println("Cats count is " + Cat.count);
    public static class Cat
        public static int count = 0;

asked 14 Mar '15, 04:51

Rajat's gravatar image

accept rate: 0%

edited 14 Mar '15, 08:37

Elleonora%20Carry's gravatar image

Elleonora Carry ♦♦

you will have to call the class constructor of cat . by this you can get the count value .


answered 17 Mar '15, 14:41

Muhammad%20Hassan%20Durrani's gravatar image

Muhammad Has...
accept rate: 0%

You must write your solution and people help you. Print ready solutions is prohibited the forum rules.


answered 14 Mar '15, 06:17

RabenokDmitry's gravatar image

accept rate: 14%

actually the solution is rather simple. what worked for me is that I incremented the count after each new cat.


answered 15 Mar, 10:45

Vagon's gravatar image

accept rate: 0%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "Title")
  • image?![alt text](/path/img.jpg "Title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: 14 Mar '15, 04:51

Seen: 1,806 times

Last updated: 15 Mar, 10:45