What is the result?


What is the result?
A. Compilation fails only at line n2.
B. RTool::export
Tool::export
C. Tool::export
Tool:export
D. Compilation fails only at line n1.
E. Compilation fails at both line n1 and line n2.

Download Printable PDF. VALID exam to help you PASS.

20 thoughts on “What is the result?

  1. The given code snippet has incorrect keyword ‘Interface’ i.e upper case ‘I’ instead of ‘i’
    IDE gives a compilation error.

  2. D is correct : Cannot reduce the visibility of the inherited method from Downloadable
    There is not problem with Line N2

  3. class Tool implements Exportable {
    protected void export() { // replace with public will work

    }
    }

    public class ReportTool extends Tool implements Exportable {
    public void export() {

    }

    public static void main(String[] args) {
    Tool aToll = new ReportTool();
    Tool btool = new Tool();
    callExport(aToll);
    callExport(btool);
    }

    public static void callExport(Exportable ex) {
    ex.export();
    }
    }

    interface Exportable {
    void export();
    }

  4. D :

    # javac ReportTool.java
    ReportTool.java:6: error: export() in Tool cannot implement export() in Exportable
    protected void export () {
    ^
    attempting to assign weaker access privileges; was public
    1 error

    1
    1
    1. if in “n1” position “protected” replace by “public” , this program will be compiled with no errors, with following result:

      # java ReportTool
      RTool::export
      Tool::export

  5. Answer D:

    Because the signature of the implementing methods in the first concrete class must match the signature of the abstract methods of the interface.
    In this example, the access modifier in Tool is protected, while in the interface it is default (i.e. no access modifier). Therefore the compilation fails.

    6
    4
    1. All interface methods are public by default. The problem is that we’re providing weaker access by making it protected

  6. class Tool implements Exportable{
    public void export() {
    System.out.println(“Tool::export”);
    }
    }
    public class ReportTool extends Tool implements Exportable{
    public void export() {
    System.out.println(“RTool::export”);
    }
    public static void main(String[] args) {
    Tool aToll = new ReportTool();
    Tool btool = new Tool();
    callExport(aToll);
    callExport(btool);
    }
    public static void callExport(Exportable ex) {
    ex.export();
    }
    }
    interface Exportable{
    void export();
    }

    Giving me : answer B >>

    $javac ReportTool.java
    $java -Xmx128M -Xms16M ReportTool
    RTool::export
    Tool::export

    2
    1
    1. you missed this
      class Tool implements Exportable{
      public void export() {
      System.out.println(“Tool::export”);
      }
      }
      ||
      V
      class Tool implements Exportable{
      protected void export() {
      System.out.println(“Tool::export”);
      }
      }

      answer is D

Leave a Reply

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


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