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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:13:16+00:00 2026-05-26T19:13:16+00:00

Recently I am doing a coding exercises I need to make my project ,

  • 0

Recently I am doing a coding exercises I need to make my project , and so far I am practicing it with the code below what I want to ask is that, is this a has a relationship? am I doing the right practice? look at my code, sorry for my bad english

public class Personal {

        private String firstName;
        private String middleInitial;
        private String lastName;
        private int age;

        public Personal(String firstName,String middleInitial , String lastName , int age){
            setFirstName(firstName);
            setMiddleInitial(middleInitial);
            setLastName(lastName);
            setAge(age);
        }

        public void setFirstName(String firstName){
            this.firstName = firstName;
        }

        public String getFirstName(){
            return firstName;
        }

        public void setMiddleInitial(String middleInitial){
            this.middleInitial = middleInitial;
        }

        public String getMiddleInitial(){
            return middleInitial;
        }

        public void setLastName(String lastName){
            this.lastName = lastName;
        }

        public String getLastName(){
            return lastName;
        }

        public void setAge(int age){
            this.age = age;
        }

        public int getAge(){
            return age;
        }

        public String toString(){
            return String.format("First Name: "+getFirstName()+"\nMiddle Initial: "+getMiddleInitial()+
                                    "\nLast Name: "+getLastName()+"\nAge: "+getAge());
        }
}

Contact Class

public class Contact {
    private String address;
    private String email;
    private String contactNumber;

    public Contact(String address,String contactNumber, String email){
        setAddress(address);
        setContactNumber(contactNumber);
        setEmail(email);
    }

    public void setAddress(String address){
        this.address = address;
    }

    public String getAddress(){
        return address;
    }

    public void setEmail(String email){
        this.email = email;
    }

    public String getEmail(){
        return email;
    }

    public void setContactNumber(String contactNumber){
        this.contactNumber = contactNumber;
    }

    public String getContactNumber(){
        return contactNumber;
    }

    public String toString(){
        return String.format("Address: "+getAddress()+"\nContact Number: "+getContactNumber()+
                                "\nEmail Address: "+getEmail());
    }
}

Employee Class

public class Employee {
    private Personal personal;
    private Contact contact;

    public Employee(Personal personal, Contact contact){
        this.personal = personal;
        this.contact = contact;
    }

    public void setFirstName(String firstName){
        this.personal.setFirstName(firstName);
    }

    public String toString(){
        return String.format(personal.toString()+contact.toString());
    }
}

And the Test class

public class TestClass {

    public static void main(String[] args){
        Personal personalHerp = new Personal("John","M","Doe",18);
        Contact contactHerp = new Contact("88 Herp Derp St U mad New york","724-15-70","fido.com");
        Employee employeeHerp = new Employee(personalHerp,contactHerp);
        System.out.println(employeeHerp);
    }
}
  • 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-26T19:13:17+00:00Added an answer on May 26, 2026 at 7:13 pm

    Well, since Employee doesn’t extend Personal it has a Personal and a Contact.

    I guess you’d rather like Employee to be a Personal and thus it should look like this:

    public class Employee extends Personal {
      private Contact contact;
      ...
    }
    

    So to summarize:

    • is-a means a class/object extends another class or implements an interface, i.e. A is-a B if A extends B or A implements B
    • has-a means that a class/object has a variable of that type, like Contact contact in your Employee class, which means Employee has-a contact.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I've been doing lots of weekend coding, and have began to really need
I was recently doing a programming assignment that required us to implement in code
So something I've been doing recently is adding an additional project to my code
I have Java experience and recently am doing some C++ coding. My question is
I've recently started doing some coding in Python again and I've encountered an error
I was recently doing some Windows Api coding (still doing it). And I was
I recently came across this in some code - basically someone trying to create
I have recently been doing a security code review for my company and using
I've been all over looking for a solution to this recently, and so far
I've recently started doing some JSF work - before that I've always used PHP

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.