What is the result?

Given:

And given the code fragment:

What is the result?
A. Compilation fails at line n2.
B. Read Book
C. Read E-Book
D. Compilation fails at line n1.
E. Compilation fails at line n3.

Download Printable PDF. VALID exam to help you PASS.

5 thoughts on “What is the result?

  1. All the unimplemented methods have to be implemented in the first concrete class(non abstract/interface). In Ebook we should have an implementation of download() because we’re in debt at that point

  2. E:
    # javac Test22.java
    Test22.java:15: error: EBook is not abstract and does not override abstract method download() in Downloadable
    class EBook extends Book {
    ^
    1 error

  3. Answer E:

    The interface Readable inherits all methods of Downloadable interface. Therefore, “Readable” receives a “copy” so to say, of the method “Download()”. Now comes the abstract class “Book” which implements the interface “Readable”. In normal cases, any class that implements an interface, have to implement all of the interface’s abstract methods. But because the class “Book” is abstract by nature, it is not required to directly implement the interface’s methods. However, it gives this responsibility to its first concrete class, which is in our case class “Ebook”. Therefore, class “Ebook” must implement both readBood() as well as download() methods.

    Therefore, the compilation fails at the definition of the Ebook class.

    11
  4. class EBook, since it’s the first concrete class that inherits all the abstract classes, it should implement any that haven’t been done already. So abstract class Book implements readBook(), this is fine. However download() has been forgotten about and it’s down to Ebook to implement it

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.