Ask Your Question
3

How can a default method be specifically invoked in Java?

asked 2021-07-24 11:00:00 +0000

qstack gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-06-10 11:00:00 +0000

ladyg gravatar image

A default method in Java can be specifically invoked by using the interface name followed by the method name. For example, if we have an interface named "MyInterface" with a default method "myMethod", we can invoke the default method as follows:

MyInterface obj = new MyClass();
obj.myMethod();   // Invokes the default method

Here, we have created an object of a class ("MyClass") that implements the "MyInterface". We can then use this object to invoke the default method "myMethod".

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-07-24 11:00:00 +0000

Seen: 8 times

Last updated: Jun 10 '21