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 6117069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:16:42+00:00 2026-05-23T15:16:42+00:00

Good day! I created overloading constructors as follows: public ContactsBean(String firstName, String lastName, String

  • 0

Good day!

I created overloading constructors as follows:

public ContactsBean(String firstName, String lastName,
                String telNumber, String email) {
    this.id = count;
    count = count + 1;
    this.firstName = firstName;
    this.lastName = lastName;
    this.email = email;
    this.telNumber = telNumber;
}

public ContactsBean() {
    this.id = count;
    count = count + 1;
}

I want to auto-increment the id so i used this variables:

    private static int count;   
    private int id;

My problem is, when I instantiate the ContactsBean() contacts = new ContactsBean(), the value of id is incremented by 2..
2,4,6,8… etc.

Why? How can I do the auto number of ID increment by 1?

Thank you.

EDIT:

Action:

private ContactsBean contacts = new ContactsBean();
private ContactsManager contactsManager = new ContactsManager();

    public String add() {
        contactsManager.addContacts(contacts);
        return SUCCESS;
    }

Manager:

private ContactsDAO contactsDAO = ContactsDAO.getInstance();
private List<ContactsBean> contactsList = contactsDAO.getContactsList(); 

public void addContacts(ContactsBean contact) {
    contactsList.add(contact);
}
  • 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-05-23T15:16:43+00:00Added an answer on May 23, 2026 at 3:16 pm

    First, DRY (do not repeat yourself), would be better:

        public ContactsBean(String firstName, String lastName,
                    String telNumber, String email){
        this();
        this.firstName = firstName;
        this.lastName = lastName;
        this.email = email;
        this.telNumber = telNumber;
    }
    

    Second, there is no increment by two in your code. Please paste in your test code.

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

Sidebar

Related Questions

Good day! I created jar file (using Netbeans) and i can't start it. This
Good day! I noticed that in anonymous event handler this is referenced to global
Good Day, I have created an asp.net web service on my local machine, and
Good Day, I have a number of binary strings that were created by a
Good day! I created two classes namely Setting and Game; In my game access
Good day to all. I have a site (created with zend framework and smarty)
Good day to all. I have an odd error. I have created a chat
Good day to all. I have this setup: One page with text/whatever, that also
Good day, I've done some research looking for this answer, but haven't had much
Good day. I could really use your help on this one. I have 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.