Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Q1: [2] Answer the following questions based on the following code: interface Libraryltems ( void use() { System.out.println( I will use a library item.);

Q1: [2] Answer the following questions based on the following code: interface Libraryltems ( void use() { System.out.println(" I will use a library item."); } } class Book implements Libraryltems { public void use () { System.out.println("I am reading a book."); } } class PrintedBooks extends Book { public void use () { System.out.println("I am reading a printed book."); } } class AudioBooks extends Book { public void use () { System.out.println("I am listening to an audiBook."); } } class moviesDVDs implements Libraryltems { public void use() { System.out.println("I am watching moviesDVD."); } } public class PolymorphRef{ public static void main(String[] args) { Book] LibraryBooks = (new Printed Books (), new AudioBooks()); // (1) Libraryltems [] items = (new Book(), new PrintedBooks(), new moviesDVDs ()}; // (2) System.out.println("Using LibraryBooks:"); for (int i = 0; i < LibraryBooks.length; i++) LibraryBooks[i].use(); System.out.println("Using library items:"); for (int i = 0; i < items.length; i++) items[i].use(); a. b. // (4) // (3) Is it possible to create an object from the Libraryltems class. Explain why? There are compile errors in the program above. What is/are all the statement(s) that make the error? C. What is the output of this program, if you correct the error. d. Draw a complete class diagram that shows the relationships between all the classes defined in the program above. ( you must show different types of arrows depending of the type of class)

Step by Step Solution

3.43 Rating (156 Votes )

There are 3 Steps involved in it

Step: 1

c d Following is the correct executable Java code as follows Java Code ... 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

Introduction to Algorithms

Authors: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest

3rd edition

978-0262033848

More Books

Students also viewed these Algorithms questions

Question

Would you investigate to learn more about this Club? How?

Answered: 1 week ago