Skip to content

Instantly share code, notes, and snippets.

@hassanshahzadaheer
Forked from jimmykurian/Instructor.java
Created June 13, 2016 21:37
Show Gist options
  • Save hassanshahzadaheer/9b6264dadb73c3a0c12ca66ccda8ac1c to your computer and use it in GitHub Desktop.
Save hassanshahzadaheer/9b6264dadb73c3a0c12ca66ccda8ac1c to your computer and use it in GitHub Desktop.
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.
//Instructor.java - 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=" + super.toString() + ",salary=" + salary + "]";
}
}
//Person.java - 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 + "]";
}
}
//PersonTester.java - 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);
System.out.println(a);
System.out.println(b);
System.out.println(c);
}
}
//Student.java - 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=" + super.toString() + ",major=" + major + "]";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment