- Java MCQ Topics
- Operators & Assignments
- Regular Expressions
- Garbage Collection
- Exception Handling
- File Handling
- Flow Control
- Inheritance
- Abstract Class
- Command Line Arguments
- Java Programming Reference
- Learn Java Programming
- Java Programming Books
- Java Interview Questions
- Java Coding Questions
- Java Programming Quiz
- Other Reference
- Quantitative Aptitude
- Learn Firebase
- Android Books
Java MCQ Questions - Operators & Assignments
This section focuses on the "operators and assignments" in Java programming. These Multiple Choice Questions (MCQ) should be practiced to improve the Java programming skills required for various interviews (campus interviews, walk-in interviews, company interviews), placements and other competitive examinations.
A. Characters B. Boolean C. Numeric D. Both Numeric & Characters
Explanation: The operand of arithmetic operators can be any of numeric or character type, But not boolean.
A. Both Integers and floating - point numbers B. Integers C. Floating - point numbers D. None of the mentioned
Explanation: Modulus operator can be applied to both integers and floating point numbers..
A. 1 B. 2 C. 3 D. 4
Explanation: Decrement operator, −−, decreases the value of variable by 1.
A. Assignment operators can be used only with numeric and character data type B. Assignment operators are more efficiently implemented by Java run-time system than their equivalent long forms C. Assignment operators run faster than their equivalent long forms D. None of the mentioned
Explanation: None of the mentioned.
A. TRUE B. FALSE C. Can be true or false D. can not say
Explanation: Both data types have different memory representation that is why 8-byte integral data type can be stored to 4-byte floating point data type.
A. 14 B. 12 C. 13 D. 10
Explanation: Output of the expression is 13.
A. ( ) B. { } C. Both A & B D. None of these
Explanation: Parentheses(), Array subscript{} and Member selection- have the same precedence.
A. Compare two boolean values B. Compare two numeric values C. Combine two boolean values D. Combine two numeric values
Explanation: Logical AND(&&) and Logical OR(||) combine two boolean values.
A. ((x 1)) && (x B. ((x 1)) || (x C. (1 > x > 100) || (x D. 1
Explanation: No explanation.
A. \\ B. \v C. \a D. \t
A. 12 15 B. 15 15 C. 3 7 5 3 7 5 D. 3 4 5 3 7 5
Explanation: The reference variables a1 and a3 refer to the same long array object. When the [1] element is updated in the fix() method, it is updating the array referred to by a1. The reference variable a2 refers to the same array object. So Output: 3+7+5+"" ""3+7+5 Output: 15 15 Because Numeric values will be added
A. true true B. true false C. false true D. false false
Explanation: The boolean b1 in the fix() method is a different boolean than the b1 in the start() method. The b1 in the start() method is not updated by the fix() method.
A. s st B. sst st C. st s st D. sst s st
Explanation: When the fix() method is first entered, start()'s s1 and fix()'s s1 reference variables both refer to the same String object (with a value of ""s""). Fix()'s s1 is reassigned to a new object that is created when the concatenation occurs (this second String object has a value of ""sst""). When the program returns to start(), another String object is created, referred to by s2 and with a value of ""st"".
A. (int)Math.min(d); B. (int)Math.abs(d); C. (int)Math.max(d); D. (int)Math.floor(d);
Explanation: The casting to an int is a smokescreen.
A. Compiler Error: Operator >> cannot be applied to negative numbers B. -2 2 C. 2 D. 2 2
Explanation: No explantion.
A. 1, 2 & 3 B. 1 & 4 C. 1, 2, 3 & 4 D. 3 & 2
Explanation: Operator ++ increases value of variable by 1. x = x + 1 can also be written in shorthand form as x += 1. Also x =+ 1 will set the value of x to 1.
A. 0 1 B. 1 1 C. 1.5 1 D. 1.5 1.0
Explanation: No Explanation.
A. s B. t C. h D. Compilation fails
Explanation: This is an example of a nested ternary operator. The second evaluation (x < 22) is true, so the ""t"" value is assigned to sup.
A. 7 B. 0 C. 14 D. 8
Explanation: The & operator produces a 1 bit when both bits are 1. The result of the & operation is 9. The ^ operator produces a 1 bit when exactly one bit is 1; the result of this operation is 10. The | operator produces a 1 bit when at least one bit is 1; the result of this operation is 14.
A. 44 B. 56 C. 48 D. 40
Explanation: Operator ++ has more preference than *, thus g becomes 4 and when multiplied by 8 gives 32.
A. Integer B. Boolean C. Characters D. Double
Explanation: None.
A. Integers B. Floating - point numbers C. Boolean D. None of the mentioned
Explanation: All relational operators return a boolean value ie. true and false.
A. && B. == C. ?: D. +=
Explanation: Operator Short circuit AND, &&, equal to, == , ternary if-then-else, ?:, are boolean logical operators. += is an arithmetic operator it can operate only on numeric values.
A. ! B. | C. & D. &&
Explanation: Operator short circuit and, &&, and short circuit or, ||, skip evaluating right hand operand when output can be determined by left operand alone.
A. true and false are numeric values 1 and 0 B. true and false are numeric values 0 and 1 C. true is any non zero value and false is 0 D. true and false are non numeric values
Explanation: True and false are keywords, they are non numeric values which do not relate to zero or non zero numbers. true and false are boolean values.
A. 1 B. 0 C. TRUE D. FALSE
Explanation: Operator > returns a boolean value. 5 is not greater than 6 therefore false is returned. output: $ javac Relational_operator.java $ java Relational_operator false
A. 0 B. 1 C. 3 D. -4
Explanation: None. output: $ javac ternary_operator.java $ java ternary_operator 3
A. 1 B. 2 C. Runtime error owing to division by zero in if condition D. Unpredictable behavior of program
Explanation: Operator short circuit and, &&, skips evaluating right hand operand if left hand operand is false thus division by zero in if condition does not give an error. output: $ javac Output.java $ java Output 2
A. 0 B. 1 C. FALSE D. TRUE
Explanation: None. output: $ javac Output.java $ java Output false
A. () B. ++ C. * D. >>
Explanation: Order of precedence is (highest to lowest) a -> b -> c -> d.
A. Integer B. Floating - point numbers C. Boolean D. None of the mentioned
Explanation: The controlling condition of ternary operator must evaluate to boolean.
A. 0 B. 1 C. 9 D. 8
A. 1 -> 2 -> 3 B. 2 -> 1 -> 3 C. 3 -> 2 -> 1 D. 2 -> 3 -> 1
A. 10 B. 11 C. 12 D. 56
Explanation: Operator ++ has the highest precedence than / , * and +. var2 is incremented to 7 and then used in expression, var3 = 7 * 5 / 7 + 7, gives 12. output: $ javac operators.java $ java operators 12
A. 24 8 B. 24 9 C. 27 8 D. 27 9
Explanation: Operator ++ has higher precedence than multiplication operator, *, x is incremented to 9 than multiplied with 3 giving 27. output: $ javac operators.java $ java operators 27 9
Also check :
- Bootstrap Courses
- Best Sql Tutorial
* You must be logged in to add comment.