Java MCQs - Solutions

CoderIndeed
0

Q1. Which of the following will import only static members of java.util.Arrays class?
Answer: import static java.util.Arrays;

Q2. Which of the following is not a property of a JVM?
Answer: It prevents Java bytecode from being easily decoded/decompiled.

Q3. Object which can store group of other objects is called
Answer: Collection object

Q4. Non-static nested classes have access to __  from enclosing class.
Answer: All the members

Q5. What will be the output for the following code snippet?

ArrayList a1 = new ArrayList();
a1.add("Ravi");
a1.add("Vijay");
Iterator it = a1.iterator();
System.out.println(it.next());
Answer: Ravi

Q6. Choose the correct option to fill the below code
Answer: sc.nextInt(); sc.next(); sc.nextDouble();  

Q7. Which of the statement is incorrect?
Answer: Every class must contain a main() method.

Q8. What is the output the following code?
Answer: 1

Q9. If there are 5 classes, E is derived from D, D from C, C from B and B from A. which class construct will be called first if the object of E or D is created?
Answer: A

Q10. What will be the output of the following code?
Answer: a.y = 5
              b.y = 6  
              a.x = 2
             b.x = 2
             IdentifyMyParts.x = 2

Q11. We want this code to print the titles of each book twice. Why doesn’t it?
Answer: None of the above. The code does print each book title twice.

Q12. What will be the output for the following code snippet?

HashMap map = new HashMap();
map.put(1, "E-Box");
map.put(2, "Learning and Assessment");
map.put(3, "Platform");
map.remove(0);
System.out.println("Values after remove: "+map);
Answer: Values after remove: {1=E-Box, 2=Learning and Assessment, 3=Platform}

Q13. How to convert Date object to String?
Answer: SimpleDateFormat sdf = new SimpleDateFormat(“yyyy-mm-dd”);
Sdf.format(new Date());

Q14. If an exception occurs within the ___ block, the appropriate exception-handler that is associated with the try block handles the exception.
Answer: try

Q15. Choose the correct option based on this program?
Answer: When executed, this program prints the following: “The removed element is: 1”

Q16. Choose the option that contains only primitive literals.
Answer: 1.2D, 1f, ‘c’

Q17. What is the output of this program?
Answer: The program runs fine and displays x[0] is 0.

Q18. What is one of the most important reasons that Java supports extending classes via inheritance?
Answer: Developers minimize duplicate code in new classes by sharing code in a common parent class.

Q19. Predict the output.
Answer: [Char, acte, r de, cide, s th, e re, spec, t]

Q20. Consider the following code snippet.
If you deserialize the object and print the field term (term is declared as int and is not a transient), what will it print?
Answer: 57

« Go Back

Post a Comment

0Comments

Post a Comment (0)

#buttons=(Accept !) #days=(20)

Our website uses cookies to enhance your experience. Check Now
Accept !