Question: public class Student extends Person { //Data Members private String StudentID; private String Course; private String Category; //Default Constructor public Student() { super(); this.StudentID =
public class Student extends Person {
//Data Members
private String StudentID;
private String Course;
private String Category;
//Default Constructor
public Student()
{
super();
this.StudentID = "Unknown";
this.Course = "Unknown";
this.Category = "Unknown";
}
//Non-default Constructor
public Student(String FN, String LN, int Age, String GN, String City, String SID, String Course, String Cat)
{
super (FN, LN, Age, GN, City);
this.StudentID = SID;
this.Course = Course;
this.Category = Cat;
}
public String toString()
{
String Print;
Print = " Student Details:" + super.toString() + " Student ID: " + this.StudentID + " Course: " + this.Course +
" Category: " + this.Category;
return Print;
}
}
Student Class
Consider student class as a sub class of Person
- What is the additional attribute that a student 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.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
