Question: Create an interface RoleDisplayable to require a void method displayNameAndRole ( ) a . Code a default method for displayNameAndRole ( ) that makes all
Create an interface RoleDisplayable to require a void method displayNameAndRole
a Code a default method for displayNameAndRole that makes all Student instances display
the name with Student after the name.
b Important: if its not a Student, lets make the default method do nothing. Maybe not
great design, but it will make this lab more interesting! How will you do this??
c Also important: if you try to invoke getName from your default method, youll get a
compile error! Remember static and dynamic types? getName is in the dynamic type
Student! To solve this problem, well need to add a cast before the
dot and method call something like this: Student this
Make class Student implement RoleDisplayable.
Write a test driver in main that
a builds an ArrayList of objects, populated with some Student objects. do
it fast: copy and paste and edit lines of code that add
Iterate through the list using a foreach loop in invoking the default
displayNameAndRole
Now, make Instructor class implement RoleDisplayable.
a In Instructor, override the displayNameAndRole method so an Instructor object has the
correct title displayed
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
