In your main method, create a student object and an instructorobject.
Suppose we are designing a simple college record-keeping program that has records for students and faculty. There is a natural hierarchy for grouping these record types: They are all records of people (inheriting from class Person). Students. They have the following properties: o Name, Student Number, Major, and Level (freshman, sophomore, junior, senior) ● Instructors. Instructors have the following properties: o Name, ID, Salary. However, the salary is a property in the job class (can be found below: In your main method, create a student object and an instructor object. public class Job { private String role; private long salary; private int id; public String getRole(){ return role; } public void setRole(String role){ this.role = role; } public long getSalary(){ return salary; } public void setSalary(long salary){ this.salary = salary; public int getId(){
public class Person { //composition has-a relationship private Job job; public Person () { } this.job=new Job(); } public long getSalary(){ job.setSalary(1000L); } return job.getSalary(); public class TestPerson { public static void main(String[] args) { Person person = new Person(); long salary = person.getSalary();
In your main method, create a student object and an instructor object.
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am