0% found this document useful (0 votes)
8 views3 pages

Java Inheritance: Person Class Structure

The document defines a Person class with subclasses Student and Instructor. Person has a name and birth year. Student adds a major and Instructor adds a salary. The code tests creating objects of each class and printing them.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Java Inheritance: Person Class Structure

The document defines a Person class with subclasses Student and Instructor. Person has a name and birth year. Student adds a major and Instructor adds a salary. The code tests creating objects of each class and printing them.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

jimmykurian / Instructor.

java Sign in Sign up

A super class Person with two subclasses, Student and Instructor, that inherit from Person. A person has a name and a
year of birth. A student has a major, and an instructor has a salary.

[Link]

//[Link] - Jimmy Kurian

public class Instructor extends Person


{
private double salary;

public Instructor(String n, int byear, double s)


    {
      super(n, byear);
      salary = s;
    }

    public String toString()


    {
      return "Employee[super=" + [Link]() + ",salary=" + salary + "]";
    }
}

[Link]

//[Link] - Jimmy Kurian

public class Person


{
private String name;
private int birthYear;

public Person(String n, int byear)


{
name = n;
birthYear = byear;
}

public String toString()


{
return "Person[name=" + name + ",birthYear=" + birthYear + "]";
}
}

[Link]

//[Link] - Jimmy Kurian

public class PersonTester


{
  public static void main(String[] args)
  {
    Person a = new Person("Anil", 1992);
    Student b = new Student("Jimmy", 1919, "Information Technology");
    Instructor c = new Instructor("Mike", 1998, 95000);
    [Link](a);
    [Link](b);
    [Link](c);
  }
}

[Link]

//[Link] - Jimmy Kurian

public class Student extends Person


{
  private String major;

  public Student(String n, int byear, String m)


  {
     super(n, byear);
     major = m;
  }

  public String toString()


  {
    return "Student[super=" + [Link]() + ",major=" + major + "]";
  }
}

red-caprica
commented about 1 year ago

Great Job on this. Super simple


Comment on gist

Sign in to comment

or sign up to join this conversation on GitHub

Desktop version

You might also like