Java Operators and Type Conversion MCQs: 10 Solved Questions with Output Traces

Practise ten Java questions on relational, logical, arithmetic, bitwise and equality rules. Each solution follows operand types, values and side effects.

KnowledgeGate Team

Exam prep & CS education

Updated 4 Dec 20267 min read
Java Operators and Type Conversion MCQs: 10 Solved Questions with Output Traces

Java output questions often hide the decisive rule in the operand types, evaluation order or the difference between primitive values and wrapper references. Identify the operator first, write the operand types beside it, and only then trace the value, using this Java syntax and OOP refresher if you need to rebuild the base. The ten MCQs below give checkable working for each answer.

The published Operators in Java: Types, Precedence and Runnable Examples explains operator semantics and precedence; this set focuses on exam-style conversion, side-effect and output traces.

Java relational and logical operators: recognise valid symbols first

Start with two quick checks. Java writes greater-than-or-equal as >=, never =>; its logical AND, OR and NOT operators are &&, || and !, while the single & used later can operate bit by bit on integers.

Question 1

MCQ, DSSSB 2021, use the operators/type-conversion practice hub (question page unavailable)

Which of the following is a invalid relational operator in Java?

  • (a) <=

  • (b) =>

  • (c) !=

  • (d) ==

Answer: (b) =>. Java recognises <=, >=, != and == among these choices. Option (b) reverses the required characters, so the precise correction is => to >=.

Question 2

MCQ, MPPSC 2025

In JAVA, symbols of Boolean operators &&, || and ! are respectively represented as

  • (a) NAND, NOR and XOR

  • (b) AND, OR and NOT

  • (c) NOT, OR and AND

  • (d) OR, AND and NOT

Answer: (b) AND, OR and NOT. The mapping in order is && for AND, || for OR and prefix ! for NOT. A direct check gives true && false = false, true || false = true and !true = false.

Java integer division: conversion happens after the expression

In double var1 = 8/3, both operands are int, so Java computes the integer quotient 2 before widening it to 2.0. By contrast, 8.0/3 has a floating-point operand and produces approximately 2.6666666666666665; the Java's operator and type-conversion rules decide the answers here.

Question 3

MCQ, UPPSC Polytechnic Lecturer 2021, see the integer-division solution

In Java: double var1 = 8/3; System.out.println(var1); prints which among the following:

  • (a) 2

  • (b) 2.0

  • (c) 3.0

  • (d) 2.7

Answer: (b) 2.0. Integer division gives quotient 2 and remainder 2 because 8 = 3 x 2 + 2. Assignment then widens 2 to 2.0; the target type cannot retroactively turn 8/3 into floating-point division.

Question 4

What will be the output of the following Java code?

java
public class Test {
    public static void main(String[] args) {
        int a = 5;
        int b = 2;
        System.out.println(a / b);
    }
}
  • (a) 2.5

  • (b) 2

  • (c) 3

  • (d) 2.0

Answer: (b) 2. Both variables are int, so 5/2 produces quotient 2 and discards remainder 1. The check 5 = 2 x 2 + 1 confirms the result, and no floating-point assignment adds a decimal point.

Java numeric promotion and implicit widening

Binary numeric promotion can widen an operand for an expression, while assignment conversion widens the completed result for storage. Keep those stages separate: comparison changes the working types, while a wider target changes how an already computed value is represented.

Question 5

MCQ, UPPSC Polytechnic Lecturer 2021.

Java statement: System.out.println(2 == 2.0); what does it print?

  • (a) Prints true

  • (b) Prints false

  • (c) Will not compile successfully

  • (d) Compiles but raises exception

Answer: (a) Prints true. Java promotes the integer 2 to double 2.0, making the comparison 2.0 == 2.0. These are primitive numeric values, unlike the Integer references compared in Question 10.

Question 6

Which Java concept converts a smaller data type to a larger one automatically? Java का कौन-सा कॉन्सेप्ट छोटे डेटा टाइप को बड़े डेटा टाइप में अपने आप (automatically) परिवर्तित करता है?

  • (a) Explicit casting एक्सप्लिसिट कास्टिंग

  • (b) Implicit casting इम्प्लिसिट कास्टिंग

  • (c) Boxing बॉक्सिंग

  • (d) Conversion कन्वर्ज़न

Answer: (b) Implicit casting इम्प्लिसिट कास्टिंग. In byte b = 12; int i = b; double d = i;, automatic widening carries the value through 12, 12 and 12.0. By contrast, int n = (int) 12.9 is explicit narrowing and produces 12 by discarding the fractional part.

Java bitwise operators and narrowing casts: trace the bits

A shift first promotes a byte to a 32-bit int; a later (byte) cast then retains only the low eight bits. For &, align equal-width binary forms and retain a 1 only in positions where both inputs contain 1.

Question 7

MCQ, DSSSB 2021, use the operators/type-conversion practice hub (question page unavailable)

What is the output of the given java code?

java
byte x = 64, y;
y = (byte) (x << 4);
system.out.println(y);
  • (a) 0

  • (b) 128

  • (c) 256

  • (d) 32

As written, lowercase system does not compile. Java is case-sensitive, and the class name is System; that result is absent from the options. With the intended spelling System.out.println(y), the answer is (a) 0: 64 = 0x00000040, and promotion followed by the shift gives 64 x 16 = 1024 = 0x00000400. Casting back to byte retains low byte 0x00, so y is decimal 0.

Four-panel Java diagram shows byte 64 promoted to int, shifted left to 1024, narrowed to low byte zero, with a lowercase-system compile note.

Question 8

MCQ, DSSSB 2023

What is the expected output of the following Java code?

java
    public static void main(String[] args) {
        int a = 5;
        int b = 7;
        System.out.println("a&b = " + (a & b));
    }
  • (a) a&b = 5

  • (b) a&b = 7

  • (c) a&b = 35

  • (d) a&b = 2

Answer: (a) a&b = 5. Aligning four-bit forms gives 5 = 0101, 7 = 0111 and 0101 & 0111 = 0101, which is decimal 5. The single & operates on individual bits here, so it is neither multiplication (5 x 7 = 35) nor logical &&.

Java post-increment: use the old value, then update the variable

Post-increment contributes the current value to its expression and updates the variable as a side effect. A short trace prevents you from adding the incremented values too early.

Question 9

Post-increment trace: y and z contribute old values 10 and 12, then update to 11 and 13 while x becomes 22.

MCQ, ISRO 2011, see the post-increment trace

In Java, after executing the following code what are the values of x, y and z? int x,y=10, z=12; x=y++ + z++;

  • (a) x=22, y=10, z=12

  • (b) x=24, y=10, z=12

  • (c) x=24, y=11, z=13

  • (d) x=22, y=11, z=13

Trace stage

Values of variables

Values consumed or produced

Before the expression

y=10, z=12

No operands consumed yet

Evaluate y++ + z++

Old values are used

x = 10 + 12 = 22

After both side effects

y=11, z=13

Final x=22

Answer: (d) x=22, y=11, z=13. The old values 10 and 12 feed the addition, giving 22; the increments then remain visible in the variables. The same tracing habit transfers to these

Java wrapper equality: values and references differ

Primitive == compares numeric values after promotion, as Question 5 showed. When both operands are Integer objects, == instead asks whether the two references point to the same object.

Question 10

java
public class Kg
{
public static void main(String[] args)
{
// Assume the OpenJDK/HotSpot reference JVM's default Integer cache configuration (upper bound = 127; i.e., no -XX:AutoBoxCacheMax / -Djava.lang.Integer.IntegerCache.high override)
Integer a = 128, b = 128;
System.out.println(a == b);
Integer c = 100, d = 100;
System.out.println(c == d);
}
}
  • (a) true true

  • (b) 128 100

  • (c) false true

  • (d) error

Answer: (c) false true. Under the cache configuration stated in the stem, separate autoboxings of 128 produce different references, while 100 is cached and both variables receive the same reference. The output is false on the first line and true on the second; a.equals(b) would compare wrapped values and return true for either numeric pair.

Java operators and type conversion revision map

Revision area

Questions

Check to write before answering

Syntax recognition

1 and 2

>=; &&, `

, !`

Integer division

3 and 4

Operand types decide 8/3=2 and 5/2=2

Promotion and widening

5 and 6

2 becomes 2.0; 12 becomes 12.0

Bits and side effects

7 to 9

1024 to low byte 0; 0101 & 0111 = 0101; 10+12=22, then increment

Wrapper identity

10

128 gives false; 100 gives true under the stated cache assumption

Re-attempt Questions 3, 7, 9 and 10 without their explanations. They test four different failure points: expression type, narrowing bits, evaluation timing and reference identity.

For a structured route through the language, use the Java Course, Concepts, MCQs & Coding Questions; the Complete Java Course is a second full-course option. The Coding & Skill Development Courses page is the broader route if you are comparing Java with other coding tracks. The short version is to mark each operand's type, evaluate the operator, and apply conversion or side effects only at the stage where Java does.