Use the class and interface headers below. public interface Readable public inte
ID: 3677932 • Letter: U
Question
Use the class and interface headers below.
public interface Readable
public interface Downloadable
public abstract class Book implements Readable
public class Dictionary extends Book
public class eBook extends Book implements Downloadable
Which of the following are legal assignments:
Readable r = new Readable(...)
Readable r = new Book(...)
Readable r = new Dictionary(...)
Readable r = new eBook(...)
Book b = new Book(...)
Book b = new Dictionary(...)
Book b = new eBook(...)
Dictionary d = new Dictionary(..)
Downloadable d = new Downloadable(...)
Downloadable d = new Book(...)
Downloadable d = new Dictionary(...)
Downloadable d = new eBook(...)
Readable[] readableThings = new Readable[10]
Book[] books = new Book[10]
Dictionary[] dictionaries = new Dictionary[10]
Explanation / Answer
INTERFACE:
An interface in java is a blueprint of a class. It has static constants and abstract methods only.
The interface in java is a mechanism to achieve fully abstraction. There can be only abstract methods in the java interface not method body. It is used to achieve fully abstraction and multiple inheritance in Java.
Java Interface also represents IS-A relationship
IMPLEMENTS AND EXTENDS:
The distinction is that implements means that you're using the elements of a Java Interface in your class, and extends means that you are creating a subclass of the class you are extending. You can only extend one class in your new class, but you can implement as many interfaces as you would like.
Based on the declarations given above
Readable r = new Readable(...) = not valid
Readable r = new Book(...) = not valid
Readable r = new Dictionary(...) = valid
Readable r = new eBook(...) = valid
Book b = new Book(...) = not valid
Book b = new Dictionary(...) = valid
Book b = new eBook(...) = valid
Dictionary d = new Dictionary(..) = valid
Downloadable d = new Downloadable(...) = not valid
Downloadable d = new Book(...) = not valid
Downloadable d = new Dictionary(...) = not valid
Downloadable d = new eBook(...) = valid
Readable[] readableThings = new Readable[10] = valid
Book[] books = new Book[10] = valid
Dictionary[] dictionaries = new Dictionary[10] = valid
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.