Overloaded method for null in Java

0 votes

I have the below method:

JOptionPane.showInputDialog(null, "Hello World!!");

Can someone explain, if I call the above method, which of the following overloaded method will be invoked and why:

  • showInputDialog(Component parent, Object message)

  • showInputDialog(Object message, Object initialSelectionValue)

May 23, 2018 in Java by v.liyyah
• 1,290 points
45 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

The method invoked here will be the one which is most specific to the condition. So the one to be called here is:

showInputDialog(Component parent, Object message)

Determining which method is to be invoked, is based on the "Determine Method Signature(15.12.2) step of overload resolution in the spec, and in particular "Choosing the Most Specific Method" (15.12.2.5).

According to this spec, "If more than one member method is both accessible and applicable to a method invocation, it is necessary to choose one to provide the descriptor for the run-time method dispatch. The Java programming language uses the rule that the most specific method is chosen." (read more...)

answered May 23, 2018 by code.reaper12
• 3,450 points

Related Questions In Java

0 votes
1 answer

Method for escaping HTML in Java

242 StringEscapeUtils from Apache Commons Lang: import static org.apache.commons.lang.StringEscapeUtils.escapeHtml; // ... String source ...READ MORE

answered Jan 9 in Java by developer_1
• 3,280 points
76 views
0 votes
1 answer

I am learning looping statements. Can you tell me how 'for-each' works in Java?

While programming we often write code that ...READ MORE

answered Apr 17, 2018 in Java by Rishabh
• 3,520 points
35 views
0 votes
1 answer

concat() vs “+” operator : In Java for String concatenation

Basically, there are two important differences between ...READ MORE

answered Apr 27, 2018 in Java by Rishabh
• 3,520 points
610 views
0 votes
1 answer

Why the main() method in Java is always static?

As you might know, static here is ...READ MORE

answered May 8, 2018 in Java by geek.erkami
• 2,320 points
239 views
0 votes
2 answers

“Could not find or load main class” mean?

Use the final modifier to enforce good initialization. Avoid returning ...READ MORE

answered Sep 18, 2018 in Java by Sushmita
• 6,840 points
1,321 views
0 votes
2 answers

What is the use of toString method in Java and how can I use it ?

Whenever you require to explore the constructor ...READ MORE

answered Aug 23, 2018 in Java by Daisy
• 8,040 points
221 views
0 votes
1 answer

How do I replace character from string at specific indexes?

String are immutable in Java. You can't ...READ MORE

answered Apr 26, 2018 in Java by Rishabh
• 3,520 points
30 views
0 votes
2 answers

When to use Static Methods in Java?

A static method has two main purposes: For ...READ MORE

answered Aug 9, 2018 in Java by samarth295
• 2,190 points
67 views
0 votes
1 answer

Need for finalize() in Java

finalize() is a method called by the ...READ MORE

answered May 8, 2018 in Java by code.reaper12
• 3,450 points
59 views
0 votes
1 answer

Overriding private or static method in Java

You cannot override a private or static ...READ MORE

answered Jul 30, 2018 in Java by code.reaper12
• 3,450 points
60 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.