Answered step by step
Verified Expert Solution
Link Copied!

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)
.
2. Make class Student implement RoleDisplayable.
3. 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 -10 lines of code that add()...]
4. Iterate through the list using a for-each loop in , invoking the [default]
displayNameAndRole()
5. 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro SQL Server Administration

Authors: Peter Carter

1st Edition

1484207106, 9781484207109

More Books

Students also viewed these Databases questions

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago