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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:42:08+00:00 2026-06-13T05:42:08+00:00

I am confused on how to get parameters from new object instances to also

  • 0

I am confused on how to get parameters from new object instances to also flow into the super class to update the private fields in teh super class.

So I am in an advanced Java class and I have homework that requires a “Person” Super Class and a “Student” subclass that extends Person.

The Person class stores the student name BUT it is the Student class constructor that accepts the Person name.

assume no method in Person to make a variable method update…like subClassVar = setSuperClassVar();

EX:

public class Person
{
     private String name; //holds the name of the person
     private boolean mood; //holds the mood happy or sad for the person
     private int dollars; //holds their bank account balance
}

class Student extends Person //I also have a tutor class that will extend Person as well
{
     private String degreeMajor //holds the var for the student's major they have for their degree

     Public Student(String startName, int startDollars, boolean startMood, String major)
     {
          degreeMajor = major;  // easily passed to the Student class
          name = startName; //can't pass cause private in super class?
          mood = startMood; //can't pass cause private in super class?
          dollars = startDollars; // see above comments
          // or I can try to pass vars as below as alternate solution...
          setName() = startName; // setName() would be a setter method in the superclass to...
                                 // ...update the name var in the Person Superclass. Possible?
          setMood() = startMood; // as above
          // These methods do not yet exist and I am only semi confident on their "exact"...
          // ...coding to make them work but I think I could manage.
     }   
}

The instructions for the homework were a bit vague in terms of how much changing to the superclass of Person I am allowed to make so if you all believe a good solid industry accepted solution involves changing the superclass I will do that.

Some possible examples I see would be to make the private vars in Person class “protected” or to add setMethods() in the person class and then call them in the sub class.

I am also open to general concept education on how to pass subclass contstructor parameters to a super class…and if possible do that right in the constructor portion of the code.

Lastly, I did search around but most of the similiar questions were really specific and complicated code….I couldnt find anything straight forward like my example above…also for some reason the forum post did not clump all of my code together so sorry for the confusing read above.

Thanks all.

  • 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-13T05:42:10+00:00Added an answer on June 13, 2026 at 5:42 am

    First, you need to define a constructor for Person:

    public Person(String startName, int startDollars, boolean startMood)
    {
        name = startName;
        dollars = startDollars;
        mood = startMood;
    }
    

    Then you can pass data up from the Student constructor using super(...):

    public Student(String startName, int startDollars, boolean startMood, String major)
    {
        super(startName, startDollars, startMood);
        . . .
    }
    

    Alternatively, you can define setters in the Person class and invoke them from the Student constructor.

    public class Person
    {
         private String name; //holds the name of the person
         private boolean mood; //holds the mood happy or sad for the person
         private int dollars; //holds their bank account balance
    
         public void setName(String name) {
             this.name = name;
         }
         // etc.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Am farely new to JSF and I get easily confused between JSF and Facelets
I get confused when I see examples of self invoked anonymous functions in Javascript
I always get confused when I am about to use a bit map to
Well - the more I read the more confused I get. So here the
I am trying to write this loop in Python but get confused. Basically I
I am starting to use JPA and I always get confused with the term
I am a beginner in Knockout and I must say I often get confused
This is a very simple question for compiler guys, but I always get confused
I get very much confused when it comes to pointers. I want to know
confused - given a track uri, I can get one album but possibly more

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.