Java MockTest

#### What does JVM stand for? 1. [ ] Java Visual Machine 2. [x] Java Virtual Machine 3. [ ] Java Virtual Memory 4. [ ] Java Virtual Method #### Which keyword is used to define a constant in Java? 1. [ ] constant 2. [x] final 3. [ ] static 4. [ ] const #### What is the output of the following code snippet? ```java int x = 5; System.out.println(x++ + ++x); ``` 1. [ ] 10 2. [ ] 11 3. [x] 12 4. [ ] 13 #### What is the default value of a boolean variable in Java? 1. [x] false 2. [ ] true 3. [ ] 0 4. [ ] 1 #### What does the "this" keyword refer to in Java? 1. [x] Current class instance 2. [ ] Parent class instance 3. [ ] Subclass instance 4. [ ] Static variable #### What is the parent class of all classes in Java? 1. [x] Object 2. [ ] Main 3. [ ] Super 4. [ ] None of the above #### Which of the following is not a primitive data type in Java? 1. [ ] int 2. [ ] float 3. [x] string 4. [ ] char #### What does the "break" keyword do in Java? 1. [x] Exits the current loop or switch statement 2. [ ] Continues to the next iteration of the loop 3. [ ] Jumps to a specific label 4. [ ] Terminates the program #### Which collection class allows you to associate a unique key with a value in Java? 1. [ ] ArrayList 2. [x] HashMap 3. [ ] LinkedList 4. [ ] TreeSet #### What is the access level of a default modifier in Java? 1. [ ] Private 2. [ ] Protected 3. [ ] Public 4. [x] Package-private #### What is the result of 10 % 3 in Java? 1. [ ] 0 2. [x] 1 3. [ ] 2 4. [ ] 3 #### What is the main purpose of the "super" keyword in Java? 1. [x] To call the superclass constructor 2. [ ] To access the superclass methods and fields 3. [ ] To define a superclass 4. [ ] To initialize an object #### Which keyword is used to declare a method that cannot be overridden in Java? 1. [x] final 2. [ ] static 3. [ ] abstract 4. [ ] private #### What is the difference between == and .equals() method in Java? 1. [ ] They are equivalent 2. [x] == compares object references, .equals() compares object contents 3. [ ] .equals() compares object references, == compares object contents 4. [ ] They both compare object contents #### What is the output of the following code snippet? ``` java String str1 = "hello"; String str2 = "hello"; System.out.println(str1 == str2); ``` 1. [x] true 2. [ ] false 3. [ ] Compilation error 4. [ ] Runtime error #### Which of the following statements is true about interfaces in Java? 1. [ ] Interfaces can contain constructors 2. [ ] Interfaces can contain instance variables 3. [x] A class can implement multiple interfaces 4. [ ] Interfaces can extend classes #### What is the output of the following code snippet? ``` java int[ ] arr = {1, 2, 3, 4, 5}; System.out.println(arr.length); ``` 1. [ ] 1 2. [x] 5 3. [ ] 4 4. [ ] Compilation error #### Which of the following is not a type of loop in Java? 1. [ ] for 2. [x] foreach 3. [ ] do-while 4. [ ] while #### Which keyword is used to prevent method overriding in Java? 1. [x] final 2. [ ] static 3. [ ] abstract 4. [ ] private #### What is the purpose of the "toString()" method in Java? 1. [x] To convert an object to a string 2. [ ] To convert a string to an object 3. [ ] To compare two objects 4. [ ] To clone an object


Table of Contents