Write a superclass called Person (as shown in the class diagram), which contains: Two instance variables name
Fantastic news! We've Found the answer you've been seeking!
Question:
Write a superclass called ؛Person (as shown in the class diagram), which contains:
- Two instance variables name (String) and address (String).
- Two constructors: a (no-argument) constructor that initializes the name to "Ahmed" and address to “Gaza”, and a constructor that initializes the name and address to the given values.
- Getter and setter for all the instance variables.
- A toString() method that returns "A Person with name of xxx and address of yyy
Write a test program to test all the methods defined in Person.
Write two subclasses of Person called Student and Staff, as shown in the class diagram.
The Student class contains:
- An instances variable program (String), year(int) and fee(double) .
- One constructor as shown.
- Getter and setter for the instances variable program , year and fee.
- Override the toString() method inherited, to return "A Student with [name,address]
,[program,year and fee].
The Staff class contains:
- Two instance variables school (String) and pay (double).
- One constructor as shown.
- Getter and setter for all the instance variables.
- Override the toString() method inherited, to return "A Staff [name,address],[school,pay]
Ex: Superclass Person and its subclasses Student and Staff
Related Book For
Posted Date: