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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:53:02+00:00 2026-06-15T20:53:02+00:00

Okay, so I have 4 different classes for my program, and I’m trying to

  • 0

Okay, so I have 4 different classes for my program, and I’m trying to add a new variable in one of my subclasses. I will show the code for all of the classes involved and then explain what exactly is wrong.

First Code is my Person Class:

class Person {
private String myName; // name of the person
private int myAge; // person's age
private String myGender; // 'M' for male, 'F' for female

// constructor
public Person(String name, int age, String gender) {
    myName = name;
    myAge = age;
    myGender = gender;
}

public String getName() {
    return myName;
}

public int getAge() {
    return myAge;
}

public String getGender() {
    return myGender;
}

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

public void setAge(int age) {
    myAge = age;
}

public void setGender(String gender) {
    myGender = gender;
}

public String toString() {
    return myName + ", age: " + myAge + ", gender: " + myGender;
}

}

my next class is my Teacher Class:

public class Teacher extends Person {
private static int salary;
private static String subject;

public Teacher(String name, int age, String gender, String subject, int salary) {
    super(name, age, gender);
    //Constructor
    salary = salary;
    subject = subject;
    public String toString(){


    return super.toString() +", Subject: " + subject + " Salary: " + salary;
}
}

}

So the problem with my program is, I’m trying to add in the String Subject and the Int Salary. I’m getting an error that keeps saying “Syntax error on token “String”, @ expected”(Line 12 of the Teacher Class) and then another one right next to it saying:””Syntax error, insert “EnumBody” to complete BlockStatement”(line 12 of the Teacher Class).

So all I am trying to do is add the new values into my parent class so that when I go to add in a user I can enter their salary and subject and so on. Sorry if i’m not too clear. It might be in plain sight for some of you, if i’m not clear enough please let me know.

Any help is greatly appreciated!

Thanks,
Sully

  • 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-15T20:53:03+00:00Added an answer on June 15, 2026 at 8:53 pm

    I haven’t looked all through your code, but I believe this is the problem:

    public Teacher(String name, int age, String gender, String subject, int salary) {
        super(name, age, gender);
        //Constructor
        salary = salary;
        subject = subject;
        public String toString(){
    
        return super.toString() +", Subject: " + subject + " Salary: " + salary;
    }
    

    You’ve started overriding toString in the middle of the constructor. You need to close the constructor, then start the toString method:

    public Teacher(String name, int age, String gender, String subject, int salary) {
        super(name, age, gender);
        //Constructor
        salary = salary;
        subject = subject;
    }
    
    public String toString() {    
        return super.toString() + ", Subject: " + subject + " Salary: " + salary;
    }
    

    Ideally, use the @Override annotation to tell the compiler to validate that you really are overriding a superclass method, too:

    @Override
    public String toString() {    
        return super.toString() + ", Subject: " + subject + " Salary: " + salary;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay I have updated my code quite a bit. I am getting a new
Okay I have two classes for two links and two divs with different information.
okay i have been trying to understand this for hours i am learning VB
Okay I have updated my code a little, but I am still not exactly
Okay so i have this code: if (isset($_GET['book'])) { $query= SELECT book_id, title, authors.`author`
Okay I have created an application where in one of the screens I have
I have code similar to the following in one of my jinja template {%
Okay so I have been trying to get into IoC lately. However, I keep
Okay, so here's a problem I'm running into. I have some classes in my
Okay, I am writing a function that will allow many different types of bullets

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.