Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6805567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:36:08+00:00 2026-05-26T19:36:08+00:00

Following is the code relevant to constructor overloading in Java. Let’s have a look

  • 0

Following is the code relevant to constructor overloading in Java. Let’s have a look at it.

package temp;

final public class Main
{
    private Main(Object o)
    {
        System.out.println("Object");
    }

    private Main(double[] da)
    {
        System.out.println("double array");
    }

    public static void main(String[] args)throws Exception
    {
        Main main = new Main(null);
    }
}

In the above code, constructors are being overloaded in which one has a formal parameter of type Object and the other has the formal parameter of type double (array).


Main main = new Main(null);

One of the constructors is being invoked by the above statement which is using a null value as it’s actual argument and the program is displaying the output double array on the console. How does the compiler resolve a specific constructor (or a method, if such is a case) dynamically at run time in such a situation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T19:36:09+00:00Added an answer on May 26, 2026 at 7:36 pm

    It’s resolved at compile time to double[], because it’s the most specific member to resolve to:

    If more than one member method is both accessible and applicable to a method invocation, […] The Java programming language uses the rule that the most specific method is chosen.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's look at the following code snippet in Java. package trickyjava; class A {
I have a class MemoryPool with the following (shortened to relevant) code: namespace System
I have a transparent BufferedImage created with the following code(not relevant how it is
Here is my problem in C# : I have the following classes: public class
My problem is related to Android. I have the following code (non-relevant parts omitted):
I have following code (only relevant portions shown for sake of brevity - please
I have the following C++ code that I'm trying to get to compile (relevant
The following code is in the /Courses/Detail action: [AcceptVerbs(GET)] public ActionResult Detail(int id) {
I have a main function in A.cpp which has the following relevant two lines
Reviewing a quite old project I found the following curious code snippet (only relevant

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.