Inheritance 2
Inheritance 2
Scanner;
class info
{ Scanner ob = new Scanner(System.in);
String name;
String fname;
int phoneNo;
void getdata( )
{ System.out.print(" Put name: ");
name = ob.nextLine();
System.out.print(" Put Father Name: ");
fname = ob.nextLine();
System.out.print(" Phone No: ");
phoneNo = ob.nextInt();
}
void putData( )
{ System.out.println(" Name: "+name);
System.out.println(" Father Name: "+fname);
System.out.println(" Phone No: "+phoneNo);
}
}
class student extends info // info is base class and student is derived class
{ int ID;
String major;
float GPA;
void getStData( )
{
System.out.print(" Put ID: ");
ID = ob.nextInt();
ob.nextLine();// to clear input buffer
System.out.print(" Put Major Feild: ");
major = ob.nextLine();
System.out.print(" GPA: ");
GPA = ob.nextFloat();
}
void putStData( )
{ System.out.println(" Student ID: "+ID);
System.out.println(" Major Field: "+major);
System.out.println(" Grade: "+GPA);
}
class teacher extends info // info is base class and teacher is derived
class
{ int teacherID;
String jobTitle;
int salary;
void getTeacherData( )
{
System.out.print(" Put Teacher's ID: ");
teacherID = ob.nextInt();
ob.nextLine();// to clear input buffer
System.out.print(" Put Position: ");
jobTitle = ob.nextLine();
System.out.print(" Salary: ");
salary = ob.nextInt();
}
void putTeacherData( )
{ System.out.println(" Teacher ID: "+teacherID);
System.out.println(" Position: "+jobTitle);
System.out.println(" Salary: "+salary);
}
class staff extends info // info is base class and staff is derived class
{ int Staff_ID;
String job;
String college_name;
void getStaffData( )
{
System.out.print(" Put Staff_ID: ");
Staff_ID = ob.nextInt();
ob.nextLine();// to clear input buffer
System.out.print(" Put Job Title of Staff: ");
job = ob.nextLine();
System.out.print(" Put College_Name: ");
college_name = ob.nextLine();
}
void putStaffData( )
{ System.out.println(" Staff_ID: "+Staff_ID);
System.out.println(" Job Title : "+job);
System.out.println(" College_Name: "+college_name);
}