Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started