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,300 points
920 views

1 answer to this question.

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,500 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, 2019 in Java by developer_1
• 3,350 points
4,444 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,620 points
954 views
+1 vote
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,620 points
4,771 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 9, 2018 in Java by geek.erkami
• 2,680 points
2,116 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,920 points
4,553 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,140 points
4,132 views
0 votes
2 answers

How do I replace character from string at specific indexes?

You could turn the String into a ...READ MORE

answered Aug 22, 2019 in Java by Sirajul
• 59,230 points
23,836 views
0 votes
2 answers

When to use Static Methods in Java?

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

answered Aug 10, 2018 in Java by samarth295
• 2,220 points
16,112 views
0 votes
1 answer

Need for finalize() in Java

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

answered May 9, 2018 in Java by code.reaper12
• 3,500 points
704 views
0 votes
1 answer

Overriding private or static method in Java

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

answered Jul 31, 2018 in Java by code.reaper12
• 3,500 points
16,546 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP