Java Varargs or Variable Arguments Interview MCQ Questions and Answers

Study and learn Interview MCQ Questions and Answers on Varargs or Variable Arguments in Java. Attend job interviews easily with these Multiple Choice Questions. You can print these Questions in default mode to conduct exams directly. You can download these MCQs in PDF format by Choosing Print Option first and Save as PDF option next using any Web Browser.

Go through Java Theory Notes on Varargs before reading these objective questions.



1) Java Varargs are applicable only for ___.
A) Constructors
B) Methods
C) Both Constructors and Methods
D) None
Answer [=]
Answer[=]
2) A Java-Vararg is nothing but ____.
A) Variable number of arguments
B) Variable type of arguments
C) Variable size of arguments
D) All
Answer [=]
Answer[=]
3) A Java vararg is a ____.
A) Method
B) Constructor
C) Variable
D) All
Answer [=]
Answer[=]
4) A Java-Vararg can be of any type like primitive or object type. State TRUE or FALSE.
A) TRUE
B) FALSE
C) -
D) -
Answer [=]
Answer[=]
5) A Java Vararg or Variable Argument can come at any position in a method or constructor. State TRUE or FALSE.
A) FALSE
B) TRUE
C) -
D) -
Answer [=]
Answer[=]
6) What is the output of the below java program with varargs?
public class Varargs1
{
  static void displayStudents(String... stu)
  {
    for(String s: stu)
      System.out.print(s + " ");
  }
  public static void main(String args[])
  {
    displayStudents("Bean", "Atkinson", "Milton");
  }
}
A) Bean Bean Bean
B) null null null
C) Bean Atkinson Milton 
D) Compiler error
Answer [=]
Answer[=]
7) What is the output of the below Java program with Variable arguments?
public class Varargs2
{
  void attendance(String... allStu)
  {
    System.out.println("Attended: " + allStu.length);
  }
  void attendance(boolean... all)
  {
    System.out.println("Attended: " + all.length);
  }
  public static void main(String args[])
  {
    new Varargs2().attendance();
  }
}
A)
Attended: 0
B)
Attended: 0
Attended: 0
C) No Output
D) Compiler Error
Answer [=]
Answer[=]


 

8) Which is the error thrown when two methods with varargs look the same to the compiler?
A) The method is ambiguous
B) The method is difficult to choose
C) The method signature is not correct
D) None
Answer [=]
Answer[=]
9) What is the output of the below Java program with Varargs?
public class Varargs3
{
  Varargs3(int... dates)
  {
    System.out.println("Inside Varargs(int...)");
  }
  Varargs3(boolean... yesno)
  {
    System.out.println("Inside Varargs(float...)");
  }
  public static void main(String[] args)
  {
    new Varargs3();
  }
}
A)
Inside Varargs(int...)
B)
Inside Varargs(boolean...)
C)
Inside Varargs(int...)
Inside Varargs(boolean...)
D) Compiler error
Answer [=]
Answer[=]
10) What is the output of the below Java program with Varargs?
public class Varargs4
{
  Varargs4(int... carnums)
  {
    System.out.println("Inside Varargs(int...)");
  }
  Varargs4(float... prices)
  {
    System.out.println("Inside Varargs(float...)");
  }
  public static void main(String[] args)
  {
    new Varargs4();
  }
}
A)
Inside Varargs(int...)
B)
Inside Varargs(int...)
Inside Varargs(float...)
C) No output
D) Compiler error
Answer [=]
Answer[=]
11) What is the output of the below code snippet?
public class Varargs5
{
  Varargs5(int...weights, boolean yesno)
  {
    System.out.println("AMAZON");
  }
  public static void main(String[] args)
  {
   //new Varargs5(20, true);
  }
}
A) No output
B) Error: The variable argument type int of the method Varargs5 must be the last parameter
C) Error: Varargs do not allow other data types
D) None
Answer [=]
Answer[=]
12) Which is the operator used to represent a Vararg type in a method or constructor in Java?
A) One Dot (.)
B) Two Dots (..)
C) Three Dots (...)
D) DOT DOT DOT COMMA (...,)
Answer [=]
Answer[=]
13) How many maximum numbers of Varargs or Variable-Arguments can be there in a method or a constructor in Java?
A) 1
B) 2
C) 8
D) 16
Answer [=]
Answer[=]
14) What is the maximum number of methods or constructors with Varargs in a single Java class?
A) 1
B) 2
C) 8
D) There is no limit
Answer [=]
Answer[=]


 



Like or Share

Show some care. Like or Subscribe. [FB]...[Youtube]

C MCQ App by ExamTray 

Android APP

Java MCQ App by ExamTray 

Android APP
ALL MCQ App by ExamTray Android APP

Ad

 

Try Some Java Books

Book Price
1. Java - The Complete Reference  Check Price
2. Core Java: An Integrated Approach, Black Book Check Price
3. Java All-in-One for Dummies Check Price
4. OCP Java SE 8: Programmer II Check Price
5. Programming with Java Check Price
6. Head First Java Check Price

We may get some affiliate commission for the above purchases.