Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8470789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:37:06+00:00 2026-06-10T16:37:06+00:00

I have a question that was in an older test and I need to

  • 0

I have a question that was in an older test and I need to know the answer for practicing.

We have the following Class:

public class First{
    private int num1 = 0;
    private int num2 = 0;
    private static int count = 0;
    public First(int num){
        this(num,num);
        count++;
        System.out.println("First constructor1");
    }
    public First(int num1, int num2){
        this.num1 = num1;
        this.num2 = num2;
        count++;
        System.out.println("First constructor2");
    }
    public int sum(){
        return num1 + num2;
    }
    public static int getCount(){
        return count;
    }
}

Now we are operating the following orders:

1. First f1 = new First(10);
2. First f2 = new First(4,7);
3. System.out.println("sum1 = " + f1.sum());
4. System.out.println("count = " + First.getCount());
5. System.out.println("sum2 = " + f2.sum());
6. System.out.println("count = " + First.getCount());

I need to write down the lines that will be printed on screen after those 6 lines.
I know that after the first 3 lines it should be like this:

First constructor2
First constructor1
First constructor2
sum1 = 20

The only thing that disturb me is, what’s the meaning of a line like line #4? is it a method that operate on the class itself instead on an object?

Another question is that in part B we need to re-define the method equals inside the ‘First’ class (same method that extends Object) so she will be able to compare between the object that the method operates on and another ‘First’ type object. The method returns true if both num1, num2 are equals.

I thought about something like this:

public class First {
...
...
.
.
.

    public boolean equals (First anotherObj){
        if ((First.num1 == anotherObj.num1) && (First.num2 == anotherObj.num2))
            return true;
        return false;
    } // equals
} // 'First' class

Am I right?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T16:37:08+00:00Added an answer on June 10, 2026 at 4:37 pm

    Yes, getCount() is a static method of your class First which can be called without instantiating any concrete objects. So in your example by using this method you can read the static variable count, which gets increased by 1 whenever the constructor gets called. So if once you created f1 and f2 count will be 2. “count” is a variable shared by all your First instances.

    Your equals() method doesn’t work since first of all you need to override

    public boolean equals(Object obj)
    

    Secondly, num1 and num2 are private so you need a Getter to make them available.
    Something like:

    public boolean equals(Object obj) {
      return num1 == (First)obj.getNum1() && num2 == (First)obj.getNum2();
    }
    

    If you override equals you should also override public int hashCode()

    Example for hashCode():

    public int hashCode() {
      int result = 5;
      result = 31 * result + num1;
      result = 31 * result + num2;
      return result; 
    

    }

    (5 and 31 are primes, you can also use e.g. Eclipse to automatically generate this methods).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question that may be quite naive, but I feel the need
I have a SQL question that i need to ask the experts. To be
I have a question that should be quick and easy for you guys to
I have a question that I just don't feel like I've found a satisfactory
I have a question that I'm ashamed to ask, but I'm going to have
I have a question that may sound odd, but being somewhat of a newbie,
I have a question that can I use AS400ConnectionPool in Spring if then pls
I have a question that's somewhat of an extension of this thread . I
I have a quick question that I can't seem to find online. I am
I have seen this question that talks about getting the last part of a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.