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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:35:15+00:00 2026-06-14T06:35:15+00:00

I’m trying to make program that has a Person class with one field :

  • 0

I’m trying to make program that has a Person class with one field : name(String) and accessor and mutator. and then make a second class Student ( extends Person class) – one field: id and accessor and mutator of id. then to test it make an object and assign name and id and print out result.

This is what I have so far:

Person Class:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package person;

/**
 *
 * @author Administrator
 */
public class Person {

    /**
     * @param args the command line arguments
     */

    private String name;

    public void setName(String n)
    {
        name = n;
    }

    public String getName(String n)
    {
        return name;
    }
}

Student class //I think this is the class with the extension:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package person;


public class Student extends Person {

    public int idNumber;

    Student(String name, int idNumber) {

    }

    public void setID(int id)
    {
        idNumber = id;
    }

    public int getID(int id)
    {
        return idNumber;
    }

}

and then the main class to test the result:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package person;

import java.util.Scanner;

/**
 *
 * @author Administrator
 */
public class MainStudentID {


    public static void main(String[] args)
    {
        Scanner keyboard = new Scanner(System.in);

        System.out.println("Enter Students name: ");
        String name = keyboard.nextLine();

        System.out.println("Enter Students ID Number:");
        int idNumber = keyboard.nextInt();


        Student Student = new Student(name, idNumber);

        System.out.println("Your name is: " + Student.person.getName());
        System.out.println("Your id Number is: " + Student.Student.getID());




    }

}

I’m not sure what I am doing wrong, and I apologize for my crappy code, first time learning about the topic of class extensions.

  • 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-14T06:35:16+00:00Added an answer on June 14, 2026 at 6:35 am

    You need to set the values of name and id in your Student constructor. You’re not storing them which is why you’re not getting a result when you try to print.

    You also need to get rid of the parameters in your get methods.

    Person Class:

    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package person;
    
    /**
     *
     * @author Administrator
     */
    public class Person {
    
        /**
         * @param args the command line arguments
         */
    
        private String name;
    
        public Person(String n)
        {
            name = n;
        }
    
        public void setName(String n)
        {
            name = n;
        }
    
        public String getName()
        {
            return name;
        }
    }
    

    Student class

    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package person;
    
    
    public class Student extends Person {
    
        public int idNumber;
    
        Student(String name, int idNumber) {
            super(name);
            this.idNumber = idNumber;
        }
    
        public void setID(int id)
        {
            idNumber = id;
        }
    
        public int getID()
        {
            return idNumber;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is

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.