What will be the output upon executing main method<br /> <br /> public class Graph {<br />    private static Multimap<Integer,Integer> adjacentDirectedNodesMap = ArrayListMultimap.create();<br />    <br />    Graph(){<br />       adjacentDirectedNodesMap.put(1, 2);<br />       adjacentDirectedNodesMap.put(1, 3);<br />       adjacentDirectedNodesMap.put(1, 4);<br />       adjacentDirectedNodesMap.put(3, 5);<br />       adjacentDirectedNodesMap.put(4, 5);<br />    }<br />    <br />    public static void main(String[] args){<br />       ArrayList visited = new ArrayList();<br />       <br />       Integer startNode = 1;<br />       <br />       for(Integer adjacentNodes: adjacentDirectedNodesMap.get(startNode)){<br />             System.out.println(adjacentNodes);<br />       }<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. What will be the output upon executing main method

public class Graph {
   private static Multimap<Integer,Integer> adjacentDirectedNodesMap = ArrayListMultimap.create();
   
   Graph(){
      adjacentDirectedNodesMap.put(1, 2);
      adjacentDirectedNodesMap.put(1, 3);
      adjacentDirectedNodesMap.put(1, 4);
      adjacentDirectedNodesMap.put(3, 5);
      adjacentDirectedNodesMap.put(4, 5);
   }
   
   public static void main(String[] args){
      ArrayList visited = new ArrayList();
      
      Integer startNode = 1;
      
      for(Integer adjacentNodes: adjacentDirectedNodesMap.get(startNode)){
            System.out.println(adjacentNodes);
      }
   }   
}
Core Java
Ans. Nothing as we haven't yet created an instance and hence adjacentDirectedNodesMap won't be initialized with any value and hence is empty.

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

   Like         Discuss         Correct / Improve     constructor


Related Questions

  What are the common uses of "this" keyword in java ?
  Can we use both "this()" and "super()" in a constructor ?
  Why every object constructor automatically call super() in Object before its own constructors?
  Can constructors be synchronized in Java ?
  Does Constructor creates the object ?
 What are constructors and Destructors in Java ?
  Are constructors inherited? Can a subclass call the parent's class constructor? When?
  Difference between object instantiation and construction ?
  How can we create objects if we make the constructor private ?
  Difference Between this() and super() ?



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: