Java Interface Static and Private Method Invocation

Answer Correct answer: A, E — new MyC().m2() invokes the default method, and IFace.m3() invokes the static method.

Given: Which two method invocations execute? (Choose two.) - image

  1. new MyC().m2(); Correct Answer
  2. IFace.m4();
  3. IFace myClassObj = new MyC();
  4. IFace myClassObj = new MyC();
  5. IFace.m3(); Correct Answer

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.

Community Insight

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.

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.

Community Discussion (3 comments)

supersquax 👍 5
A and E correct!:)
SrinivasJasti 👍 1 Selected: AE
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
xplorerpj 👍 2 Selected: AE
A&E are correct

Comments & Corrections

No comments 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.

Submitted for moderation before publishing. Keep it helpful and respectful.

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 →

Related Analysis

← Back to 1Z0-829 Study Guide