Do you see any problem with this code<br /> <br /> public class BuggyBread {<br /> <br />    public static void main(String[] args) {<br />       method("Hello");<br />    }<br /> <br />    private static void method(String... args){<br />       for(String arg:args){<br />          System.out.println(arg);<br />       }<br />    }<br /> <br />    private static void method(String arg){<br />       System.out.println(arg);<br />    }<br /> }
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Interview Questions and Answers

 Q1. Do you see any problem with this code

public class BuggyBread {

   public static void main(String[] args) {
      method("Hello");
   }

   private static void method(String... args){
      for(String arg:args){
         System.out.println(arg);
      }
   }

   private static void method(String arg){
      System.out.println(arg);
   }
}
Core Java
Ans. It will compile fine and the method call will bind to method with specific argument and not with var arg

i.e private static void method(String arg)

It will print "Hello" upon execution

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     var args  methods  method declarations  functions


Related Questions

 Which of the following are valid declarations

1. void method(int... x){};
2. void method(int.. x){};
3. void method(int.. .x){};
4. void method(int ...x){};
5. void method(int... x){};
6. void method(int ... x){};
7. void method(int x, int... y){};
8. void method(int... x, int y){};
9. void method(int... x,int... y){};
 What is the difference between these two method declarations ?

private static void method(String[] arg)

and

private static void method(String... arg)
 Can we overload method as following ?

void method(int... x){};
void method(int[] x){};
  Which of the following is not valid var args declaration ?
 Do you prefer using var args ?
  Which of the following is false about var args ?
 What are var args ?

or

What is the use of var args ?
 Why following method declarations are not valid ?

void method(int... x, int y){};
void method(int... x,int... y){};
 Which method will get called if we call it as method(1)

void method(int x ){};
void method(int... x){};
 Do you see any problem with this code

public class BuggyBread {

   public static void main(String[] args) {
      method("Hello","World");
   }

   private static void method(String... args){
      for(String arg:args){
         System.out.println(arg);
      }
   }
}



Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: