Create 3 classes Person name (String) address (String) city (String) Employee de
ID: 3745832 • Letter: C
Question
Create 3 classes
Person
name (String)
address (String)
city (String)
Employee
department (String)
job (String)
pay (double)
Student
major (String)
gpa (double)
The Student and Employee classes should extend the Person class.
All of the fields should only be accessible to the class itself and public methods (getters and setters) should be created to allow retrieving values and setting values of all fields.
Each class should have a toString() method that returns a String with all field values for that class and extended class for Student and Employee.
Create a Control class that creates an instance of each of the 3 classes and demonstrate that Employee and Student are also a Person.
1. What OO principle is involved in extending a class?
2. What OO principle is involved in restricting field access (private access modifier) to only the class itself?
3. What OO principles is involved in providing a toString() method in each class?'
**Programming language is Java**
Create 3 classes
Person
name (String)
address (String)
city (String)
Employee
department (String)
job (String)
pay (double)
Student
major (String)
gpa (double)
The Student and Employee classes should extend the Person class.
All of the fields should only be accessible to the class itself and public methods (getters and setters) should be created to allow retrieving values and setting values of all fields.
Each class should have a toString() method that returns a String with all field values for that class and extended class for Student and Employee.
Create a Control class that creates an instance of each of the 3 classes and demonstrate that Employee and Student are also a Person.
1. What OO principle is involved in extending a class?
2. What OO principle is involved in restricting field access (private access modifier) to only the class itself?
3. What OO principles is involved in providing a toString() method in each class?'
**Programming language is Java**
Explanation / Answer
JavaDemo.java:
1. What OO principle is involved in extending a class?
Inheritance
2. What OO principle is involved in restricting field access (private access modifier) to only the class itself?
Encapsulation
3. What OO principles is involved in providing a toString() method in each class?'
Polymorphism