In: Computer Science
I need to see a working example using inheritance and the classes (below)
Create an application (app) that:
This code is written in java language.
Please find it.
class Person
{
String firstname;
String lastname;
byte age;
String hometown;
Person(firstname,lastname,age,hometown)
{
this.firstname=firstname;
this.lastname=lastname;
this.age=age;
this.hometown=hometown;
}
String getInfo()
{
return this.firstname+this.lastname+this.age+this.hometown;
}
}
class Student extends Person
{
byte id;
String major;
float GPA;
Student(firstname,lastname,age,hometown,id,major,GPA)
{
super(firstname,lastname,age,hometown);
this.id=id;
this.major=major;
this.GPA=GPA;
}
String getInfo()
{
return super.getInfo()+this.id+this.major+this.GPA;
}
}
class Student_athlete extends Student
{
String sport;
byte rank;
Student_athlete(firstname,lastname,age,hometown,id,major,GPA,sport,rank)
{
super(firstname,lastname,age,hometown,id,major,GPA);
this.sport=sport;
this.rank=rank;
}
String getInfo()
{
return super.getInfo()+ this.sport+this.rank;
}
}
class App
{
public static void main(String [] args)
{
Student_athlete student_athlete = new Student_athlete("robin","marshal",25,"Maryland",23,"CS",9.0,"football",23);
System.out.println(student_athlete.getInfo());
}
}