Java Interface Static and Private Method Invocation

1Z0-829 By islever Editorial Last updated

Short answer

AE New MyC().m2() invokes the default method, and IFace.m3() invokes the static method.

Question

Given: Which two method invocations execute? (Choose two.) - Exhibit: Java Interface Static and Private Method Invocation
  1. new MyC().m2(); Correct Answer
  2. IFace.m4();
  3. IFace myClassObj = new MyC();
  4. IFace myClassObj = new MyC();
  5. IFace.m3(); Correct Answer

Key Takeaways

The question tests knowledge of access rules for private and static interface members, with the common trap being confusion between static/non-static and public/private accessibility.

This Java SE 8+ question tests the ability to invoke static and private methods defined within an interface. The correct answer identifies the valid syntax for calling these specific method types directly on the interface or via instance creation.

Common mistake: Learners often select options involving instance variable assignment (C/D) without realizing they fail due to non-static/static mismatches or private access violations when attempting to call methods.

Expert Analysis

Why the Answer Is Correct

Option A is correct because m2 is a default method in the interface, which can be invoked on an instance of the implementing class MyC. Option E is correct because m3 is a static method in the interface, which must be invoked using the interface name IFace.m3.

Why the Other Options Are Wrong

Option B fails because m4 is a private method, making it inaccessible from outside the interface. Options C and D are syntactically valid assignments but do not constitute 'method invocations' as requested; furthermore, subsequent calls implied by these contexts would fail: myClassObj.m3 (calling static via instance) and myClassObj.m4 (accessing private).

Community Comment Notes

Community consensus strongly supports AE. As SrinivasJasti noted, "private method not accesible" explains why B is wrong, and "non static access of static method not possible" clarifies why calling static methods via instances is invalid.

Exam Strategy

For interface questions, immediately check if the method is static or default. Static methods require the interface name; default methods require an instance. Private methods are never accessible externally.

Frequently Asked Questions

Why can't we call IFace.m4()?

Private methods in interfaces have package-private-like scope restricted to the interface itself, so they cannot be called from outside.

Can we call static methods via an instance?

No, static methods must be called using the interface name (e.g., IFace.m3()). Calling them via an instance is a compilation error.

More 1Z0-829 FAQ →

Community Votes

AE
100%

100% of anonymous learners picked answer AE. Votes are pick records left by other test-takers — they are not the verified answer.

Discussion 3 contributions

Compiled from public community threads and reader submissions, lightly edited for clarity. Handles and vote tallies are shown as recorded, and comments reflect the views of individual contributors.

From public community threads 3

  1. SrinivasJasti 👍 1
    B. IFace.m4(); // private method not accesible C. IFace myClassObj = new MyC(); myClassObj.m3(); //non static access of static method not possible D. IFace myClassObj = new MyC(); myClassObj.m4(); // private access not possible IFace.m2(); // static access non static method not possible
  2. supersquax 👍 5
    A and E correct!:)
  3. xplorerpj 👍 2
    A&E are correct

Reader comments & corrections

No reader corrections yet — spotted an error or have a note? Share it below.

Log in to comment, report an error, or add a note about this question.

← Back to 1Z0-829 Study Guide