Question: public class Teacher extends Person { //Data Members private String TeacherID; private String Course; private String Type; //Default Constructor public Teacher() { super(); this.TeacherID =
public class Teacher extends Person {
//Data Members
private String TeacherID;
private String Course;
private String Type;
//Default Constructor
public Teacher()
{
super();
this.TeacherID = "Unknown";
this.Course = "Unknown";
this.Type = "Casual";
}
//Non-default constructor
public Teacher(String FN, String LN, int Age, String GN, String City, String TID, String Course, String Type)
{
super(FN, LN, Age, GN, City);
this.TeacherID = TID;
this.Course = Course;
this.Type = Type;
}
//toString method
public String toString()
{
String Print;
Print = " Teacher Details:" + super.toString() + " Teacher ID: " + this.TeacherID + " Course: " + this.Course +
" Type: " + this.Type;
return Print;
}
}
Teacher Class
Consider Teacher class as a sub class of Person
- What is the additional attribute that a teacher class can have?
- Discuss the different types of constructor that this class can have and how will you use Super keyword?
- Override the toString() method of person class which will display the all details of that particular person.
Create a test class and test all classes by creating their objects and by calling their toString() method.
Create a rough class diagram for above scenario.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
