Note that there are some explanatory texts on larger screens.

plurals
  1. POAdding in String and int to parent class with super.toString
    primarykey
    data
    text
    <p>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.</p> <p>First Code is my Person Class:</p> <pre><code>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; } </code></pre> <p>}</p> <p>my next class is my Teacher Class:</p> <pre><code>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; } } </code></pre> <p>}</p> <p>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).</p> <p>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.</p> <p>Any help is greatly appreciated!</p> <p>Thanks, Sully</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload