QuestionQ18

Java Object-Oriented Approach

Given:

Question Image

Which two method calls execute?

Choose two
  • A new MyC().m2();
  • B IFace.m4();
  • C IFace myClassObj = new MyC();myClassObj.m3();
  • D IFace myClassObj = new MyC();myClassObj.m4();
  • E IFace.m3();
  • F IFace.m2();
Explanation

A default interface method is a public instance method with an implementation, so MyC inherits m2 and it can be called on a MyC object. A static interface method is invoked using its declaring interface name, so IFace.m3() is valid. Private interface methods are accessible only within their declaring interface, and static interface methods are not inherited by implementing classes or available through an instance reference. Java Language Specification, Chapter 9: Interfaces

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!