Java Operators MCQs

1 min read

Java operators are special symbols and keywords used to perform operations on variables and values, governing arithmetic calculations, logical evaluations, relational comparisons, and bit-level manipulations. Divided into categories such as arithmetic (+, -, *, /, %), unary (++, --), relational (==, !=, <, >), logical (&&, ||, !), bitwise, and assignment operators, they form the core building blocks of expression evaluation in Java. Understanding operator precedence, associativity rules, short-circuit evaluation behavior, and type promotion during expression execution is crucial for writing bug-free code and succeeding in technical programming examinations.

1. Which of the following is not a primitive data type in Java?

a) int
b) boolean
c) String
d) char
Correct Answer: c) String
Explanation:
String is a built-in reference class type in Java, whereas int, boolean, and char are primitive data types.

2. What is the size of an int data type in Java?

a) 2 bytes
b) 4 bytes
c) 8 bytes
d) 16 bytes
Correct Answer: b) 4 bytes
Explanation:
An int in Java is a 32-bit signed integer, which occupies 4 bytes of memory.

3. What is the default value of an uninitialized instance variable of type int?

a) null
b) 0
c) -1
d) undefined
Correct Answer: b) 0
Explanation:
Instance variables of numeric primitive types are automatically initialized to 0 by default.

4. Which data type has a size of 8 bytes in Java?

a) int
b) float
c) long
d) short
Correct Answer: c) long
Explanation:
A long data type is 64 bits, which occupies 8 bytes of memory.

5. Which of the following variable declarations is illegal in Java?

a) int _score = 100;
b) int $value = 50;
c) int 1stNumber = 10;
d) int number1 = 5;
Correct Answer: c) int 1stNumber = 10;
Explanation:
Java identifier names cannot start with a digit, making 1stNumber illegal.

6. What is the size and range of the char data type in Java?

a) 1 byte, -128 to 127
b) 2 bytes, 0 to 65535
c) 4 bytes, 0 to 4294967295
d) 2 bytes, -32768 to 32767
Correct Answer: b) 2 bytes, 0 to 65535
Explanation:
The char data type in Java is 16-bit unsigned, occupying 2 bytes with a range from 0 to 65535 (Unicode).

7. Which keyword is used to declare a constant variable in Java?

a) const
b) constant
c) final
d) static
Correct Answer: c) final
Explanation:
The final keyword is used in Java to make a variable's value immutable after initialization.

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

a) true
b) false
c) null
d) 0
Correct Answer: b) false
Explanation:
Uninitialized boolean instance variables default to false.

9. Which type promotion rule applies when adding an int and a double in Java?

a) The double is promoted to int.
b) The int is promoted to double.
c) Both are converted to float.
d) It causes a compilation error.
Correct Answer: b) The int is promoted to double.
Explanation:
In binary numeric promotions, lower precision types like int are promoted to higher precision types like double.

10. Which of the following suffixes is required to denote a float literal explicitly in Java?

a) d or D
b) l or L
c) f or F
d) fl or FL
Correct Answer: c) f or F
Explanation:
Floating-point literals default to double, so an 'f' or 'F' suffix is required for float literals.

11. What occurs during narrowing (explicit) primitive type casting in Java?

a) Automatic conversion without data loss
b) Conversion from a larger data type to a smaller data type, potentially with data loss
c) Conversion from a smaller data type to a larger data type
d) Conversion from primitive to object reference
Correct Answer: b) Conversion from a larger data type to a smaller data type, potentially with data loss
Explanation:
Narrowing conversion requires an explicit cast and can result in truncation or loss of precision.

12. What is the default value of an object reference variable instance field in Java?

a) 0
b) false
c) null
d) empty
Correct Answer: c) null
Explanation:
Uninitialized object reference fields default to null.

13. Which of these is a valid declaration of a hexadecimal integer literal in Java?

a) int x = 0x1A;
b) int x = 1A;
c) int x = #1A;
d) int x = 0b1A;
Correct Answer: a) int x = 0x1A;
Explanation:
Hexadecimal literals in Java begin with the prefix 0x or 0X.

14. Which primitive type has a width of 16 bits and is signed?

a) byte
b) short
c) char
d) int
Correct Answer: b) short
Explanation:
The short data type is a 16-bit signed two's complement integer, whereas char is 16-bit unsigned.

15. Can local variables in Java be accessed without explicit initialization?

a) Yes, they default to zero.
b) Yes, they default to null.
c) No, local variables must be initialized before use.
d) Yes, they default to false.
Correct Answer: c) No, local variables must be initialized before use.
Explanation:
Local variables do not receive default values; the compiler enforces explicit initialization before reading them.

16. Which of the following is a valid binary integer literal introduced in Java 7?

a) int b = 0b1010;
b) int b = 2b1010;
c) int b = #1010;
d) int b = bin1010;
Correct Answer: a) int b = 0b1010;
Explanation:
Binary integer literals in Java start with the prefix 0b or 0B.

17. What is the result of widening type casting from int to long?

a) Compilation error
b) Automatic conversion with no loss of data
c) Explicit cast operator required
d) Truncation of the value
Correct Answer: b) Automatic conversion with no loss of data
Explanation:
Widening conversions happen automatically because the target type has a larger range than the source type.

18. Which wrapper class corresponds to the primitive type double?

a) Double
b) Float
c) Decimal
d) Real
Correct Answer: a) Double
Explanation:
The wrapper class for the primitive double type is Double.

19. What is the valid range of values for a byte data type in Java?

a) 0 to 255
b) -128 to 127
c) -32768 to 32767
d) 0 to 65535
Correct Answer: b) -128 to 127
Explanation:
A byte is an 8-bit signed integer ranging from -128 to 127.

20. Which of the following literals requires an explicit suffix if assigned to a long variable?

a) 100
b) 2147483648
c) 10
d) 50
Correct Answer: b) 2147483648
Explanation:
Numbers exceeding the maximum 32-bit integer limit require an L or l suffix to be recognized as long literals.

21. What happens if you assign a floating-point literal with decimal points to an int variable without casting?

a) It compiles successfully and rounds the value.
b) It causes a compilation error due to incompatible types.
c) It automatically truncates the fractional part.
d) It converts the int to a double.
Correct Answer: b) It causes a compilation error due to incompatible types.
Explanation:
Assigning a double or float literal to an int requires an explicit narrowing cast to prevent potential data loss.

22. What is the scope of a local variable in Java?

a) The entire class
b) The method or block in which it is declared
c) Across all packages
d) Available globally after declaration
Correct Answer: b) The method or block in which it is declared
Explanation:
Local variables are restricted in scope to the block or method where they are defined.

23. What is autoboxing in Java?

a) Converting a primitive type to its corresponding wrapper class object automatically
b) Converting an object to a primitive type automatically
c) Automatic garbage collection of wrapper objects
d) Wrapping classes in packages automatically
Correct Answer: a) Converting a primitive type to its corresponding wrapper class object automatically
Explanation:
Autoboxing is the automatic conversion made by the Java compiler between primitive types and their wrapper classes.

24. What is unboxing in Java?

a) Converting a wrapper object to its corresponding primitive type automatically
b) Converting a primitive to a wrapper object
c) Unzipping compressed files
d) Extracting methods from interfaces
Correct Answer: a) Converting a wrapper object to its corresponding primitive type automatically
Explanation:
Unboxing is the automatic extraction of a primitive value from a wrapper object.

25. Which of the following is a valid octal integer literal in Java?

a) int x = 012;
b) int x = 812;
c) int x = #012;
d) int x = 0o12;
Correct Answer: a) int x = 012;
Explanation:
Octal integer literals in Java begin with a leading zero (0).

26. What is the wrapper class for the primitive type boolean?

a) Boolean
b) Bool
c) Bit
d) Logical
Correct Answer: a) Boolean
Explanation:
Boolean is the wrapper class corresponding to the primitive boolean data type.

27. What is the wrapper class for the primitive type int?

a) Int
b) Integer
c) Number
d) Numeric
Correct Answer: b) Integer
Explanation:
Integer is the wrapper class corresponding to the primitive int data type.

28. Which of the following characters can be used anywhere inside an identifier name in Java?

a) Underscore (_) and dollar sign ($)
b) At sign (@) and hash (#)
c) Hyphen (-) and period (.)
d) Asterisk (*) and ampersand (&)
Correct Answer: a) Underscore (_) and dollar sign ($)
Explanation:
Java identifiers can contain letters, digits, underscores (_), and dollar signs ($).

29. What is the size of a float data type in Java?

a) 2 bytes
b) 4 bytes
c) 8 bytes
d) 16 bytes
Correct Answer: b) 4 bytes
Explanation:
A float is a 32-bit single-precision floating-point number, occupying 4 bytes.

30. What is the size of a double data type in Java?

a) 2 bytes
b) 4 bytes
c) 8 bytes
d) 16 bytes
Correct Answer: c) 8 bytes
Explanation:
A double is a 64-bit double-precision floating-point number, occupying 8 bytes.

31. Can a variable name in Java start with a number?

a) Yes, if followed by letters
b) No, variable names cannot start with a digit
c) Yes, if declared as final
d) Only inside methods
Correct Answer: b) No, variable names cannot start with a digit
Explanation:
Java variable identifiers must begin with a letter, dollar sign ($), or underscore (_), never a digit.

32. Which feature introduced in Java 7 allows underscores in numeric literals for readability?

a) Numeric underscores
b) Number separators
c) Literal spacing
d) Digit masking
Correct Answer: a) Numeric underscores
Explanation:
Java 7 allows placing underscores anywhere between digits in numeric literals to improve readability (e.g., 1_000_000).

33. What is the result of casting a double value 9.99 to an int in Java?

a) 10
b) 9
c) 9.99
d) Compilation error
Correct Answer: b) 9
Explanation:
Narrowing a floating-point value to an integer truncates the fractional part, resulting in 9.

34. Which of the following is a valid way to declare a float variable?

a) float f = 10.5;
b) float f = 10.5f;
c) float f = (float) 10.5d;
d) Both b and c
Correct Answer: d) Both b and c
Explanation:
Float literals require an 'f' or 'F' suffix, or an explicit cast from a double.

35. What is an instance variable in Java?

a) A variable declared inside a method
b) A variable declared inside a class outside any method, belonging to an object instance
c) A variable marked with the static keyword
d) A variable passed as a method parameter
Correct Answer: b) A variable declared inside a class outside any method, belonging to an object instance
Explanation:
Instance variables are non-static fields associated with specific object instances of a class.

36. What is a class (static) variable in Java?

a) A variable declared with the static keyword, shared across all instances of the class
b) A variable local to a constructor
c) A variable that cannot be changed
d) A variable stored on the stack
Correct Answer: a) A variable declared with the static keyword, shared across all instances of the class
Explanation:
Static variables belong to the class as a whole rather than any individual object instance.

37. Which of the following is true regarding primitive data types in Java?

a) They store object references in the heap.
b) They are predefined by the language and named by reserved keywords.
c) They can be subclassed.
d) They have methods associated with them directly.
Correct Answer: b) They are predefined by the language and named by reserved keywords.
Explanation:
Primitives are built-in types defined by keywords like int, char, and double.

38. What is the maximum value that can be stored in a Java byte variable?

a) 127
b) 255
c) 32767
d) 128
Correct Answer: a) 127
Explanation:
A byte is a signed 8-bit integer with a range from -128 to 127.

39. What is the minimum value that can be stored in a Java short variable?

a) 0
b) -128
c) -32768
d) -2147483648
Correct Answer: c) -32768
Explanation:
A short is a signed 16-bit integer ranging from -32768 to 32767.

40. What happens when a primitive variable is assigned to another primitive variable (e.g., int a = b;)?

a) A reference copy is created.
b) A complete independent value copy is created.
c) Both variables share the same memory location.
d) A compilation error occurs.
Correct Answer: b) A complete independent value copy is created.
Explanation:
Primitives are stored by value, so assignment copies the actual value rather than a reference.

41. Which of the following is a wrapper class for the primitive type char?

a) Character
b) Char
c) Text
d) String
Correct Answer: a) Character
Explanation:
Character is the official wrapper class for the primitive char data type.

42. Which of the following is a wrapper class for the primitive type long?

a) LongInteger
b) Long
c) BigInt
d) Int64
Correct Answer: b) Long
Explanation:
Long is the wrapper class corresponding to the primitive long data type.

43. Which of the following is a wrapper class for the primitive type short?

a) ShortInt
b) Short
c) Int16
d) Small
Correct Answer: b) Short
Explanation:
Short is the wrapper class corresponding to the primitive short data type.

44. Which of the following is a wrapper class for the primitive type byte?

a) Octet
b) Byte
c) SignByte
d) Int8
Correct Answer: b) Byte
Explanation:
Byte is the wrapper class corresponding to the primitive byte data type.

45. What is the superclass of all wrapper classes for numeric primitive types (Byte, Short, Integer, Long, Float, Double)?

a) Object
b) Number
c) Primitive
d) Value
Correct Answer: b) Number
Explanation:
The abstract class java.lang.Number is the superclass of all platform wrapper classes for numeric types.

46. Are wrapper classes in Java mutable or immutable?

a) Mutable
b) Immutable
c) Depends on the value
d) Mutable if declared with final
Correct Answer: b) Immutable
Explanation:
All wrapper classes in Java (Integer, Double, Boolean, etc.) are immutable once created.

47. What is the output of comparing two Integer objects with '==' when their values are 100?

a) true due to Integer caching (-128 to 127)
b) false because they are distinct objects
c) Compilation error
d) Runtime exception
Correct Answer: a) true due to Integer caching (-128 to 127)
Explanation:
Java caches Integer objects for values between -128 and 127, so '==' returns true due to reference sharing in that range.

48. What is the output of comparing two Integer objects with '==' when their values are 200?

a) true
b) false because values outside the cache range (-128 to 127) create separate heap objects
c) Compilation error
d) Always true
Correct Answer: b) false because values outside the cache range (-128 to 127) create separate heap objects
Explanation:
Values outside the cached range allocate new object instances, making '==' compare false for distinct memory addresses.

49. Which method is used to parse a String into a primitive int?

a) Integer.valueOf()
b) Integer.parseInt()
c) Integer.toInt()
d) String.toInt()
Correct Answer: b) Integer.parseInt()
Explanation:
Integer.parseInt() parses string input and returns a primitive int value.

50. What does Integer.valueOf("123") return?

a) A primitive int 123
b) An Integer wrapper object with value 123
c) A String "123"
d) A double 123.0
Correct Answer: b) An Integer wrapper object with value 123
Explanation:
valueOf() returns an instance of the wrapper class Integer containing the parsed number.

51. What is type promotion in arithmetic expressions with mixed types?

a) Converting smaller integer types (byte, short, char) to int before performing operations
b) Converting int to byte automatically
c) Promoting objects to strings
d) Converting double to float
Correct Answer: a) Converting smaller integer types (byte, short, char) to int before performing operations
Explanation:
In expressions, byte, short, and char values are automatically promoted to int before evaluation.

52. What happens if you add a byte and a short in Java?

a) The result is a byte.
b) The result is promoted to an int.
c) The result is a short.
d) Compilation error.
Correct Answer: b) The result is promoted to an int.
Explanation:
Arithmetic operations on byte or short operands promote both values to int, resulting in an int.

53. Which of the following assignments will cause a compilation error without explicit casting?

a) long l = 100;
b) int i = 100L;
c) double d = 50.5;
d) float f = 10.0f;
Correct Answer: b) int i = 100L;
Explanation:
Assigning a long literal (64-bit) to an int variable (32-bit) is a narrowing conversion requiring an explicit cast.

54. Can a boolean variable be cast to an int in Java?

a) Yes, true becomes 1 and false becomes 0.
b) No, boolean cannot be converted to any other primitive type.
c) Yes, using explicit casting like (int) true.
d) Yes, in conditional expressions.
Correct Answer: b) No, boolean cannot be converted to any other primitive type.
Explanation:
Java does not permit casting between boolean and numeric primitive types.

55. What is the default value of a char instance variable in Java?

a) '\u0000' (null character)
b) ' ' (space)
c) '0'
d) null
Correct Answer: a) '\u0000' (null character)
Explanation:
Uninitialized char instance variables default to the null character '\u0000'.

56. Which of the following is a valid character literal in Java?

a) "A"
b) 'A'
c) char A
d) <A>
Correct Answer: b) 'A'
Explanation:
Character literals in Java are enclosed in single quotes.

57. What is an escape sequence in Java character and string literals?

a) A sequence starting with a backslash (\) representing special characters like \n or \t
b) A way to exit loops
c) A method to terminate a program
d) A special syntax for generics
Correct Answer: a) A sequence starting with a backslash (\) representing special characters like \n or \t
Explanation:
Escape sequences use a backslash to denote formatting characters like newlines, tabs, or quotes.

58. Which escape sequence represents a newline character in Java?

a) \r
b) \n
c) \t
d) \b
Correct Answer: b) \n
Explanation:
\n denotes the newline character.

59. What is the purpose of the transient keyword on a variable?

a) To make the variable temporary and prevent it from being serialized
b) To make the variable thread-safe
c) To allocate variable memory on the stack
d) To make the variable constant
Correct Answer: a) To make the variable temporary and prevent it from being serialized
Explanation:
The transient keyword instructs the serialization mechanism to ignore the marked field.

60. What is the purpose of the volatile keyword on a variable?

a) Ensures visibility of variable changes across multiple threads
b) Makes the variable immutable
c) Deletes the variable after use
d) Speeds up mathematical calculations
Correct Answer: a) Ensures visibility of variable changes across multiple threads
Explanation:
Volatile prevents thread caching of variables, ensuring reads and writes go directly to main memory.

61. What is shadowing in Java variable scope?

a) When a local variable or parameter has the same name as an instance or static variable, hiding the outer variable within its scope
b) When a variable is deleted by garbage collection
c) When two classes share the same name
d) When inheritance hides methods
Correct Answer: a) When a local variable or parameter has the same name as an instance or static variable, hiding the outer variable within its scope
Explanation:
Variable shadowing occurs when a local declaration takes precedence over a field with the identical name.

62. How can a shadowed instance variable be accessed when a local variable has the same name?

a) Using the this keyword (e.g., this.variableName)
b) Using the super keyword
c) Using the parent keyword
d) It cannot be accessed.
Correct Answer: a) Using the this keyword (e.g., this.variableName)
Explanation:
The 'this' reference explicitly points to the current object's instance variables, bypassing local shadows.

63. Which of the following is true about final local variables?

a) They can be assigned multiple times.
b) They can be assigned once and cannot be reassigned thereafter.
c) They must always be static.
d) They receive default values automatically.
Correct Answer: b) They can be assigned once and cannot be reassigned thereafter.
Explanation:
Declaring a local variable as final permits single assignment followed by complete immutability.

64. What happens if you attempt to reassign a value to a final variable?

a) It resets successfully.
b) It throws a runtime exception.
c) It causes a compilation error.
d) The value is ignored.
Correct Answer: c) It causes a compilation error.
Explanation:
The compiler catches any subsequent assignments to final variables and halts compilation.

65. What is 'effectively final' in Java (introduced in Java 8)?

a) A variable whose value is never changed after initialization, even if not explicitly declared final
b) A variable that changes frequently
c) A variable declared with the static keyword
d) An uninitialized local variable
Correct Answer: a) A variable whose value is never changed after initialization, even if not explicitly declared final
Explanation:
An effectively final variable is one whose value does not change after its initial assignment, making it eligible for use in lambdas.

66. Can primitive types be used with Java generics directly (e.g., List<int>)?

a) Yes, starting from modern Java versions.
b) No, generics require reference types, so wrapper classes like List<Integer> must be used.
c) Yes, but only for arrays.
d) Yes, through automatic wrapping by the compiler.
Correct Answer: b) No, generics require reference types, so wrapper classes like List<Integer> must be used.
Explanation:
Generics in Java operate on reference types; primitives cannot be type parameters directly.

67. What is the memory storage location for primitive local variables in Java?

a) Heap memory
b) Stack memory
c) Code cache
d) Method area
Correct Answer: b) Stack memory
Explanation:
Local variables and primitive method arguments reside on the execution thread's stack.

68. Where are object instances and arrays stored in Java memory?

a) Stack memory
b) Heap memory
c) Register memory
d) CPU cache
Correct Answer: b) Heap memory
Explanation:
Objects and arrays are dynamically allocated on the heap.

69. What is a blank final variable in Java?

a) A final variable that is not initialized at the time of declaration
b) A variable with a null value
c) An unassigned local variable
d) A static constant
Correct Answer: a) A final variable that is not initialized at the time of declaration
Explanation:
A blank final is a final variable whose initialization is deferred until constructor execution.

70. Where must a blank final instance variable be initialized?

a) Inside every constructor of the class
b) Inside any static block
c) Inside a main method
d) It cannot be initialized.
Correct Answer: a) Inside every constructor of the class
Explanation:
Blank final instance fields must be assigned a value in every constructor before construction completes.

71. What is the output of 'System.out.println(10 + 20);'?

a) 1020
b) 30
c) Error
d) 10+20
Correct Answer: b) 30
Explanation:
Numeric addition between two integers evaluates to 30.

72. What is the output of 'System.out.println("Result: " + 10 + 20);'?

a) Result: 30
b) Result: 1020
c) 30 Result
d) Compilation error
Correct Answer: b) Result: 1020
Explanation:
String concatenation proceeds from left to right: "Result: " + 10 becomes "Result: 10", then concatenated with 20 yields "Result: 1020".

73. Which keyword is a reserved primitive data type in Java?

a) real
b) integer
c) short
d) decimal
Correct Answer: c) short
Explanation:
short is a valid primitive type keyword in Java, while real, integer, and decimal are not.

74. What is the default value of a reference array (e.g., String[] arr = new String[3];)?

a) ""
b) null
c) empty
d) Uninitialized
Correct Answer: b) null
Explanation:
Elements of a newly created reference array are initialized to null by default.

75. Can the value of a primitive variable be null?

a) Yes, for all primitives.
b) No, primitive types cannot hold null values.
c) Yes, for numeric types only.
d) Only inside wrapper classes.
Correct Answer: b) No, primitive types cannot hold null values.
Explanation:
Primitive variables store raw values, not object references, so they cannot be null.

76. Which of the following represents a valid long literal?

a) long val = 123456789;
b) long val = 123456789L;
c) long val = 123456789f;
d) long val = "123456789";
Correct Answer: b) long val = 123456789L;
Explanation:
Long literals exceeding standard integer ranges require an 'L' or 'l' suffix.

77. What happens when you perform integer division with integers in Java (e.g., 5 / 2)?

a) 2.5
b) 2
c) 3
d) 2.0
Correct Answer: b) 2
Explanation:
Integer division truncates the fractional remainder, resulting in an integer 2.

78. How can you obtain a floating-point result from dividing two integer variables a and b?

a) By casting one operand to double (e.g., (double) a / b)
b) By declaring a and b as final
c) By using integer division
d) It happens automatically.
Correct Answer: a) By casting one operand to double (e.g., (double) a / b)
Explanation:
Casting at least one operand to double promotes the division to floating-point arithmetic.

79. What is the maximum value of a 32-bit signed integer (int) approximately?

a) 32,767
b) 2.14 billion
c) 9 quintillion
d) 65,535
Correct Answer: b) 2.14 billion
Explanation:
The maximum value for a signed 32-bit int is 2,147,483,647.

80. What is the maximum value of a 64-bit signed integer (long) approximately?

a) 2.14 billion
b) 9.22 quintillion
c) 4 billion
d) 32,767
Correct Answer: b) 9.22 quintillion
Explanation:
The maximum value for a signed 64-bit long is approximately 9.22 x 10^18.

81. Which of the following is true regarding parameter passing for primitive variables in Java?

a) Primitives are passed by reference.
b) Primitives are passed by value, meaning the method receives a copy of the value.
c) Changes to the parameter inside the method affect the original variable.
d) Parameters must be declared as final.
Correct Answer: b) Primitives are passed by value, meaning the method receives a copy of the value.
Explanation:
Java is strictly pass-by-value for all variables, including primitives.

82. What is a magic number in programming in the context of variables?

a) A hard-coded numeric value in code without clear explanation
b) A random number generator
c) A cryptographic key
d) A maximum integer limit
Correct Answer: a) A hard-coded numeric value in code without clear explanation
Explanation:
Magic numbers are undocumented literal values that should ideally be replaced with named constants.

83. Why is using named constants (final variables) preferred over magic numbers?

a) It improves code readability and maintainability.
b) It speeds up compilation.
c) It reduces memory consumption on the stack.
d) It prevents garbage collection.
Correct Answer: a) It improves code readability and maintainability.
Explanation:
Named constants give meaning to values and make updates centralized and clean.

84. Can you declare a variable inside a switch expression case block without braces?

a) Yes, scoped to the entire switch block unless braces are used.
b) No, it causes a duplicate variable error across cases unless enclosed in braces.
c) Variables cannot be declared in switch blocks.
d) Only if declared as final.
Correct Answer: b) No, it causes a duplicate variable error across cases unless enclosed in braces.
Explanation:
Because case blocks share the switch scope, variable declarations without inner braces can conflict unless enclosed in block scopes.

85. What is the default value of a floating-point instance variable (float or double)?

a) 0.0
b) null
c) 1.0
d) undefined
Correct Answer: a) 0.0
Explanation:
Uninitialized floating-point instance fields default to 0.0 (or 0.0f).

86. Which of the following data types has the lowest precision in Java?

a) short
b) byte
c) int
d) long
Correct Answer: b) byte
Explanation:
Byte is an 8-bit integer, making it the smallest numeric primitive type in Java.
← Previous: Java Multithreading & Concurrency MCQs
Next →: Java Strings MCQs
Latest Java Arrays MCQs

Latest Java Arrays MCQs

In Java, an array is a dynamically allocated object used to store a fixed-size sequential collection of elements of the…

By MCQs Generator
Python Interview Questions MCQs

Python Interview Questions MCQs

Python technical interviews evaluate a candidate’s grasp of both fundamental language features and deep runtime execution mechanics. Key topics frequently…

By MCQs Generator
JavaScript Interview Questions MCQs

JavaScript Interview Questions MCQs

JavaScript interview questions evaluate a developer’s deep understanding of core language mechanics, execution models, and advanced runtime behavior. Top tech…

By MCQs Generator