1. Which of the following is NOT a feature of Java?
A) Object-orientedvB) Platform-independent C) Supports pointers like C++ D) Robust
Answer: C) Supports pointers like C++
2. The javac command is used to:
A) Run Java programs B) Compile Java source code C) Debug Java code D) Install Java libraries. Answer:
B) Compile Java source code
3. Bytecode in Java is generated by:
A) JVM. B) JDK. C) Compiler D) JRE. Answer: C) Compiler
4. Which component actually executes the Java bytecode?
A) JDK. B) JVM C) JRE D) Class Loader. Answer: B) JVM
5. In Java, a class is a:
A) Collection of methods only B) Blueprint for objects
C) Type of variable D) Reserved keyword. Answer: B) Blueprint for objects
6. Objects are created in Java using which keyword?
A) make B) build C) new D) create. Answer: C) new
7. Which of these is the correct syntax to declare a class in Java?
A) class MyClass { } B) class: MyClass { } C) MyClass class { }D) declare class MyClass { }
Answer: A) class MyClass { }
8. Instance variables are declared:
A) Inside a method B) Inside a class but outside methods C) Inside a constructor
D) As static fields only Answer: B) Inside a class but outside methods
9. Which of the following describes a constructor correctly?
A) Has the same name as the class B) Returns a value C) Is always static
D) Can be called directly without an object
Answer: A) Has the same name as the class
10. What is the default return type of a constructor in Java?
A) int B) void C) class type itself D) boolean
Answer: C) class type itself
11. Which of these is NOT a primitive type in Java?
A) int. B) double C) String D) boolean
Answer: C) String
12. What is the size of the double data type in Java?
A) 4 bytes B) 8 bytes C) 2 bytes D) 16 bytes
Answer: B) 8 bytes
13. Variables declared as static belong to:
A) Each object separately
B) The class as a whole
C) A specific method only
D) None of the above
Answer: B) The class as a whole
14. Which operator is used for object reference in Java?
A) . (dot). B) -> C) :: D) &. Answer: A) . (dot)
15. What will be the default value of an uninitialized int instance variable?
A) 0 B) null C) 1 D) undefined Answer: A) 0
16. The keyword used to define a constant in Java is:
A) final B) constant C) static D) fixed Answer: A) final
17. Which of the following is true about methods in Java?
A) Methods cannot return objects
B) Methods must always return a primitive type
C) Methods can return primitive or object types
D) Methods cannot have parameters
Answer: C) Methods can return primitive or object types
18. If no constructor is defined in a class, Java provides:
A) A private constructor
B) A default constructor
C) No constructor
D) An abstract constructor
Answer: B) A default constructor
19. Which of these is NOT an arithmetic operator in Java?
A) + B) % C) * D) && Answer: D) &&
20. The process of creating an object from a class is called:
A) Compilation
B) Instantiation
C) Declaration
D) Conversion
Answer: B) Instantiation
21. What is the scope of an instance variable?
A) Entire class but outside static methods
B) Inside constructor only
C) Inside the object created from the class
D) Entire project
Answer: C) Inside the object created from the class
22. Which of these statements is true about Java memory management?
A) Objects are allocated in stack memory
B) Objects are allocated in heap memory
C) Variables are always allocated in heap memory
D) There is no garbage collection in Java
Answer: B) Objects are allocated in heap memory
23. The method used to return the value of a private variable is usually called:
A) getMethod B) getVariable C) getter D) fetcher
Answer: C) getter
24. To set the value of a private variable, which method is typically used?
A) setVariable B) setter C) assigner D) putter
Answer: B) setter
25. Which of the following is true for reference types in Java?
A) They store actual data
B) They store memory addresses of objects
C) They are always primitive
D) They cannot be assigned null
Answer: B) They store memory addresses of objects
26. Which statement about arrays in Java is correct?
A) Arrays can hold only primitive types
B) Arrays are objects
C) Arrays cannot be passed to methods
D) Array size can change at runtime
Answer: B) Arrays are objects
27. To initialize an array of 5 integers, which syntax is correct?
A) int arr[] = new int[5];
B) int arr = int[5];
C) int arr(5) = new int;
D) int arr[5];
Answer: A) int arr[] = new int[5];
28. Which control statement is used to exit from a loop immediately?
A) exit
B) continue
C) break
D) stop
Answer: C) break
29. Which of the following best describes encapsulation in Java?
A) Hiding data and exposing behavior through methods
B) Writing all code in one class
C) Inheriting one class from another
D) Converting data to objects
Answer: A) Hiding data and exposing behavior through methods
30. Which of the following is NOT a valid identifier in Java?
A) _myVar
B) $amount
C) 2value
D) myVariable
Answer: C) 2value