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 6937213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:20:04+00:00 2026-05-27T12:20:04+00:00

The following code in Java uses varargs to overload methods. final public class Main

  • 0

The following code in Java uses varargs to overload methods.

final public class Main
{
    private void show(int []a)
    {
        for(int i=0;i<a.length;i++)
        {
            System.out.print(a[i]+"\t");
        }
    }

    private void show(Object...a)
    {
        for(int i=0;i<a.length;i++)
        {
            System.out.print(a[i]+"\t");
        }

        System.out.println("\nvarargs called");
    }

    public static void main(String... args)
    {
        int[]temp=new int[]{1,2,3,4};            

        Main main=new Main();
        main.show(temp);
        main.show();         //<-- How is this possible?
    }
}

The output of the above code is as follows.

1        2        3        4

varargs called

The last line main.show(); within the main() method invokes the show(Object...a){} method which has a varargs formal parameter. How can this statement main.show(); invoke that method which has no actual arguments?

  • 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-27T12:20:04+00:00Added an answer on May 27, 2026 at 12:20 pm

    main.show() invokes the show(Object... a) method and passes a zero-length array.

    Varargs allows you to have zero or more arguments, which is why it is legal to call it with main.show().

    Incidentally, I’d recommend that you don’t embed \n in your System.out.println statements – the ln bit in println prints a newline for you that will be appropriate for the system you’re running on. \n isn’t portable.

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

Sidebar

Related Questions

I'm confused by the following code: import java.util.ArrayList; import java.util.LinkedList; import java.util.List; public class
I wrote the following code: import java.lang.*; import DB.*; private Boolean validateInvoice(String i) {
I have the following Java code: final Future future = exeService.submit( new Runnable() {
If I have the following Java code: int[][] readAPuzzle() { Scanner input = new
The following simple program in Java uses the java.util.Random class such that it always
The following Java code sets up a Guice binding. It uses an anonymous subclass
I am a java devloper and I wish to convert following code to java
I am working on the following code: import java.io.*; import javax.xml.parsers.*; import javax.xml.transform.*; import
The following Java code is throwing a compiler error: if ( checkGameTitle(currGame) ) ArrayList<String>
Given the following Java code for generating a binary file: DataOutputStream out = new

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.