come up with an example of a *class hierarchy* of at least 2 classes you argue would be needed for an application of your choice.
import java.util.Scanner;
public class Main
{
public static void main(String[] args) {
Employee e=new Employee();
e.displayInfo();
}
}
class Employee{
private String fname;
private String lname;
private int empNo;
private int age;
private void getInfo(){
Scanner in =new Scanner(System.in);
System.out.print("First Name: ");
fname=in.next();
System.out.print("Second Name: ");
lname=in.next();
System.out.print("Employee number: ");
empNo=in.nextInt();
System.out.print("Age: ");
age=in.nextInt();
}
public void displayInfo(){
getInfo();
System.out.println("First Name: "+fname);
System.out.println("Second Name: "+lname);
System.out.println("Employee number: "+empNo);
System.out.println("Age: "+age);
}
}
Comments
Leave a comment