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

  • Home
  • SEARCH
  • 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 7459029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T13:56:00+00:00 2026-05-29T13:56:00+00:00

I saw an example that try to explain inheritance in Java. The class Employee,

  • 0

I saw an example that try to explain inheritance in Java. The class Employee, which is the base class, has three instance variables and three constructors. it is as follows:

public class Employee{
    private String name;
    private int id;

    public Employee(){

        name = " No Name!";
        id = 00100;
    }

    public Employee(String n, int i){

        name = n;
        id = i;
    }

    public Employee (Employee originalObject){

        name = originalObject.name;
        id = originalObject.id;

    }

My question is : What’s the point of the third constructor? and how it accepts an argument with the same type, Employee ,of the class that we are still working on ? The program has already an empty constructor and another one that passes String for name and int for id, so why there is an extra one that does no much more than the previous two constructors ?

  • 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-29T13:56:00+00:00Added an answer on May 29, 2026 at 1:56 pm

    It looks like the third constructor is intended to make a copy of an existing Employee object.

    You could probably do the same thing with:

    new Employee(orig.getName(), orig.getId());
    

    but that presumes that there are “get” methods for every property. It’s easier to implement one constructor like that, and then call:

    new Employee(orig);
    

    Then, if the properties of Employee need to change, you would only have to change the copy constructor in one place.

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

Sidebar

Related Questions

I saw a code example that creates a method Window_Loaded() which is called by
I saw this C# using statement in a code example: using StringFormat=System.Drawing.StringFormat; What's that
Does jQuery validation plugin have some dependencies? For example, I saw blogposts that said
i saw a example for login form same blow code class Form_Login extends Zend_Form
I try to use a simple example for better undersanding: I've got a class
i saw this example : Validate that end date is greater than start date
When I look at the example of the user extensions of GWT-Ext I saw
im looking for an example script. I saw one yesterday but for the life
From an application I need to develop, I've received a specific font that has
What is convention for local vars that has same meaning as function argument? If

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.