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
75 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,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,300 points
318 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,540 points
65 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,540 points
1,168 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,640 points
417 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,880 points
1,815 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,050 points
830 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 in Java by Sirajul
• 37,930 points
50 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
118 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
88 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
99 views