Question
package question.pkg3; public class Person { protected String myName; protected int myAge; protected String myGender; // constructor public Person(String name, int age, String gender) {
package question.pkg3;
public class Person {
protected String myName; protected int myAge; protected String myGender;
// 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; }
class Student extends Person {
protected String myIdNum; protected double myGPA;
public Student(String name, int age, String gender, String idNum, double gpa) {
super(name, age, gender); myIdNum = idNum; myGPA = gpa; }
public String getIdNum() { return myIdNum; }
public double getGPA() { return myGPA; }
public void setIdNum(String idNum) { myIdNum = idNum; }
public void setGPA(double gpa) { myGPA = gpa; }
// overrides the toString method in the parent class public String toString() { return super.toString() + ", student id: " + myIdNum + ", gpa: " + myGPA; } }
class Teacher extends Person {
protected String Subject; protected double salary;
public Teacher(String name, int age, String gender, String sub, double sal) { super(name, age, gender); Subject = sub; salary = sal; }
public String getSubject() { return Subject; }
public double getSalary() { return salary; }
public void setSubject(String sub) { Subject = sub; }
public void setSalary(double sal) { salary = sal; }
public String toString() { return super.toString() + ",Subject: " + Subject + "Salary: " + salary; } }
class CollegeStudent extends Student {
protected String Major; protected int Year;
public CollegeStudent(String name, int age, String gender, String idNum, double gpa, int year, String major) { super(name, age, gender, idNum, gpa); Major = major; Year = year; }
public String getMajor() { return Major; }
public void setMajor(String major) { Major = major; }
public int getYear() { return Year; }
public void setMajor(int year) { Year = year; }
public String toString() { return super.toString() + ", Major: " + Major + "," + "Year: " + Year; } }
public static void main(String args[]) { Person bob = new Person("Coach Bob", 27, "M"); System.out.println(bob);
Student lynne = new Student("Lynne Brooke", 16, "F", "HS95129", 3.5); System.out.println(lynne);
Teacher mrJava = new Teacher("Duke Java", 34, "M", "Computer Science", 50000); System.out.println(mrJava); CollegeStudent ima = new CollegeStudent("Ima Frosh", 18, "F", "UCB123", 4.0, 1, "Egnlish"); System.out.println(ima);
} }
I am getting this error shown above in image. Please help me to fix it.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started