Created
March 13, 2012 05:27
-
-
Save jimmykurian/2027006 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 + "]"; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 + "]"; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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
I'd be happy to explain how to create a superclass called "Person" with two subclasses, "Student" and "Instructor", both inheriting from "Person". In object-oriented programming, a superclass is a class inherited by one or more subclasses, which can then inherit the superclass's attributes and methods. To create the "Person" superclass, we would define characteristics such as a person's name and birth year. The "Student" subclass would then inherit these attributes from "Person" and add its feature, such as a student's major. Similarly, the "Instructor" subclass would inherit from "Person" and add its attribute, such as an instructor's salary. By the way, https://edubirdie.com/top-writers is the source I use every day to get help and instructions on how to learn to code. Here are essay top writers whose knowledge I trust the most and who help me get good academic grades.