Mastering Java: Test Your Knowledge

Mastering Java: Test Your Knowledge

1. What does JVM stand for in Java?

(A) Java Virtual Method
(B) Java Variable Memory
(C) Java Virtual Machine
(D) Java Verified Memory

Answer: (C) Java Virtual Machine

2. Which of the following is the correct way to declare an array in Java?

(A) int[] arr = new int[5];
(B) int arr[] = new int[5];
(C) Both a and b
(D) None of the above

Answer: (C) Both a and b

3. What is the default value of a boolean variable in Java?

(A) true
(B) false
(C) 0
(D) null

Answer: (B) false

4. Which method is used to find the length of an array in Java?

(A)length()
(B) getLength()
(C) length
(D) size()

Answer: (C) length

5. Which of the following is NOT a keyword in Java?

(A) interface
(B) extends
(C) function
(D) super

Answer: (C) function

6. Which of the following is the correct way to declare a constant in Java?

(A) final int x = 10;
(B) const int x = 10;
(C) static int x = 10;
(D) constant int x = 10;

Answer: (A) final int x = 10;

7. What is the correct syntax to print "Hello, World!" in Java?

(A)print("Hello, World!");
(B) echo("Hello, World!");
(C) System.out.print("Hello, World!");
(D) Console.WriteLine("Hello, World!");

Answer:(C) System.out.print("Hello, World!");

8. Which of the following is the entry point of a Java application?

(A) main()
(B)start()
(C) run()
(D) init()

Answer: (A) main()

9. What will be the output of the following code snippet?

 

(A) Ten
(B) Not Ten
(C) Compilation Error
(D) Runtime Error

Answer: (A) Ten

10. Which of the following access modifiers is the most restrictive in Java?

(A) public
(B) private
(C) protected
(D) default

Answer: (B) private

11. Which of the following is true about constructors in Java?

(A) Constructors can have return types
(B) A constructor name must be the same as the class name
(C) A constructor cannot be overloaded
(D) A constructor is called manually by the programmer

Answer: (B) A constructor name must be the same as the class name

12. Which of the following statements is used to create a new object in Java?

(A) new object();
(B) object.new();
(C) object = new Object();
(D) new Object();

Answer: (C) object = new Object();

13. Which of the following is used to handle exceptions in Java?

(A) catch
(B) throw
(C) try
(D)All of the above

Answer: (D) All of the above

14. Which of the following is true about the finally block in Java?

(A) The finally block is executed when an exception occurs
(B) The finally block is executed when no exception occurs
(C) The finally block is executed regardless of an exception
(D) The finally block is optional

Answer: (C) The finally block is executed regardless of an exception

15. Which of the following statements is used to terminate a loop in Java?

(A) break
(B) continue
(C) return
(D) exit

Answer: (A) break

16. Which of the following is the correct way to create an instance of a String class in Java?

(A) String s = new String("Hello");
(B) String s = "Hello";
(C) Both a and b
(D) None of the above

Answer: (C) Both a and b

17. What is the default value of a local variable in Java?

(A) 0
(B)null
(C) Undefined
(D) No default value

Answer: (D) No default value

18. Which of the following is NOT a primitive data type in Java?

(A) int
(B) float
(C) String
(D)char

Answer: (C) String

19. What is the purpose of the super keyword in Java?

(A) It refers to the parent class constructor
(B) It refers to the parent class method
(C) It refers to the current class
(D) Both a and b

Answer: (D) Both a and b

20. Which method in the Java Collection Framework is used to add an element to a list?

(A) add()
(B)insert()
(C) append()
(D) push()

Answer: (A) add()

Comments (0)
Login or create account to leave comments