Skip to content
Computer ScienceISC Class 11 · Variables and Expressions

Relational and Logical Expressions, References and Math Functions (ISC Class 11)

Updated 17 October 2026 · Fact-checked

Relational operators (< <= > >= == !=) compare values and give a boolean; logical operators && (and), || (or) and ! (not) combine booleans, with && and || short-circuiting. A variable of a class type holds a reference to an object, so assigning one object variable to another makes both refer to the same object, and == compares references while equals() compares contents. Library methods of the Math class, such as sqrt(), pow(), ceil(), floor(), round() and abs(), perform common calculations.

Assigning b = a copies the reference, so a and b share one object; == compares references, so c, a separate object, is not equal.

Illustration drawn for QuestionBuddy.

Understand Relational and Logical Expressions, Object References and Library Functions

Relational and logical expressions. a > b, a == b, a != b give true or false. Logical: ! (highest), then &&, then ||. Example: x > 2 && x < 9 || x == 20. *Short-circuit:* in A && B, B is not evaluated if A is false; in A || B, B is not evaluated if A is true. The non-short-circuit forms & and | always evaluate both sides.

Assignment expressions. Assignment gives a value, so a = b = 0 works and (n = sc.nextInt()) > 0 can be used in a condition. Do not confuse = (assign) with == (compare).

Object variables are references. Student a = new Student(); creates an object and stores its reference in a.

Student b = a;        // b refers to the same object
b.marks = 90;         // a.marks is now 90 too
Student c = new Student();   // a different object

a == b is true (same object); a == c is false. For strings, == compares references and equals() compares the characters: new String("hi") == "hi" is false but new String("hi").equals("hi") is true. A reference with no object is null; using it to call a method throws NullPointerException.

Library functions (java.lang.Math, static methods).

CallResult
Math.pow(2, 10)1024.0
Math.sqrt(144)12.0
Math.cbrt(27)3.0
Math.abs(-7.5)7.5
Math.max(3, 8.5)8.5
Math.ceil(4.2)5.0
Math.floor(-4.2)-5.0
Math.round(4.5)5
Math.round(-4.5)-4
Math.sqrt(-4)NaN

Math.random() gives a double in [0, 1). The methods are called with the class name, since they are static. Results of pow, sqrt, ceil and floor are double; round returns long (for a double argument) or int (for a float).

Relational and Logical Expressions, Object References and Library Functions: key facts

Logical precedence
  • ! first
  • then &&
  • then ||
  • Short-circuit: stop when the result is known
Left to right.
Reference rules
  • b = a copies the reference
  • == compares references
  • equals() compares contents
Objects.
Rounding functions
ceilup
floordown
roundnearest, .5 goes up
all based on the value
Math class.

How to answer Relational and Logical Expressions, Object References and Library Functions questions

Evaluate relational parts first, then combine with logic; track references as arrows.

  1. 1Evaluate each comparison to true or false.
  2. 2Apply ! then && then ||.
  3. 3For objects, note which variables point to the same object.
  4. 4For Math calls, apply the method and note the return type.

Relational and Logical Expressions, Object References and Library Functions in real life

The idea, met in an everyday situation. Answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.

Two names, one object

Suppose a school software has a Student object for Riya and a function that assigns Student s2 = s1 and then changes s2.marks to 95.

What happens to s1.marks?

Try it first, then show the solutionSolution
  1. s2 and s1 refer to the same object.
  2. Changing marks through s2 changes what s1 sees: 95.

Answer: s1.marks also becomes 95.

Memory hook: Two labels on one box.

Tricks to remember Relational and Logical Expressions, Object References and Library Functions

Short memory aids. Say each one aloud once, then use it on a question the same day.

  • And before or

    && binds tighter than ||.

    Use it when: Precedence.

  • Short circuit saves

    false && anything is false without evaluating it.

    Use it when: Logic.

  • Ceil up, floor down

    ceil(-4.2) = -4.0, floor(-4.2) = -5.0.

    Use it when: Math.

Relational and Logical Expressions, Object References and Library Functions: solved examples

Ordered from board level to HOTS. Try each one before you open the solution.

Example 1: Math method · 1 mark · MCQBoard level

The value of Math.ceil(4.2) is:
(a) 4 (b) 4.0 (c) 5.0 (d) 5

Try it first, then show the solutionSolution
  1. ceil rounds up and returns a double: 5.0.

Answer: (c) 5.0

Example 2: Math outputs · 4 marks · Short answerBoard level

Give the output: System.out.println(Math.pow(2, 10) + " " + Math.sqrt(144) + " " + Math.ceil(4.2) + " " + Math.floor(-4.2) + " " + Math.round(4.5) + " " + Math.round(-4.5) + " " + Math.abs(-7.5) + " " + Math.max(3, 8.5)); (4 marks)

Try it first, then show the solutionSolution
  1. pow gives 1024.0; sqrt gives 12.0; ceil(4.2) gives 5.0; floor(-4.2) gives -5.0.
  2. round(4.5) = 5; round(-4.5) = -4 (rounds half up towards positive infinity).
  3. abs(-7.5) = 7.5; max(3, 8.5) = 8.5.

Answer: 1024.0 12.0 5.0 -5.0 5 -4 7.5 8.5

Example 3: Logical expression · 5 marks · Short answerHarder board level

Evaluate for x = 5, y = 0: (i) x > 2 && y == 0 (ii) x < 3 || y != 0 (iii) !(x > 2) || y == 0 (iv) y != 0 && x / y > 1 (v) x > 2 || x / y > 1. Which of these avoid a division error and why? (5 marks)

Try it first, then show the solutionSolution
  1. (i) true && true = true.
  2. (ii) false || false = false.
  3. (iii) !(true) = false; false || true = true.
  4. (iv) y != 0 is false, so && stops: false; no division.
  5. (v) x > 2 is true, so || stops: true; no division.

Answer: (i) true; (ii) false; (iii) true; (iv) false; (v) true. (iv) and (v) avoid x / y because of short-circuit evaluation.

Example 4: References · 4 marks · Short answerHarder board level

Given class Box { int side; } trace: Box p = new Box(); p.side = 4; Box q = p; q.side = 9; Box r = new Box(); r.side = 9; System.out.println(p.side + " " + (p == q) + " " + (p == r) + " " + (q.side == r.side)); (4 marks)

Try it first, then show the solutionSolution
  1. q refers to the same object as p; q.side = 9 sets p.side to 9.
  2. p == q is true (same object).
  3. r is a different object: p == r is false.
  4. q.side == r.side compares the values 9 and 9: true.

Answer: 9 true false true

Example 5: Strings and references · 4 marks · Short answerHOTS / competency

Give the output and explain: String a = "hi"; String b = "hi"; String c = new String("hi"); System.out.println((a == b) + " " + (a == c) + " " + a.equals(c)); then c = null; System.out.println(c.length()); (4 marks)

Try it first, then show the solutionSolution
  1. The two literals "hi" refer to the same string object: a == b is true.
  2. new String("hi") creates a new object: a == c is false.
  3. equals compares contents: true.
  4. c = null then c.length() throws NullPointerException.

Answer: true false true; then NullPointerException when c.length() is called on null.

Where students lose marks in Relational and Logical Expressions, Object References and Library Functions

The slips examiners see most often, and what to write instead.

  • Mistake: Using == for strings

    Works for numbers.

    Wrong working

    if (s == "yes")

    Right working

    if (s.equals("yes"))

    Do this: Use equals() for content.

    Usually costs: 1-2 marks.

  • Mistake: Believing b = a copies the object

    Value thinking.

    Wrong working

    b is an independent copy

    Right working

    Both refer to one object

    Do this: Draw two arrows to one box.

    Usually costs: 2 marks.

  • Mistake: Wrong sign for round on negative halves

    Round half up.

    Wrong working

    Math.round(-4.5) = -5

    Right working

    -4

    Do this: Rounds towards positive infinity at .5.

    Usually costs: 1 mark.

Exam tips

  • Draw boxes and arrows for reference questions.
  • Mention short-circuit evaluation when a division or method call follows &&.
  • Write the return type of each Math call (double or long).

Practice questions on Relational and Logical Expressions, Object References and Library Functions

Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.

  1. Q1 · 1 mark · MCQBoard level

    The value of Math.sqrt(81) + Math.pow(2, 3) is:
    (a) 17 (b) 17.0 (c) 11.0 (d) 18.0

    Hint

    9.0 + 8.0.

    Answer

    (b) 17.0

  2. Q2 · 3 marks · Short answerBoard level

    Give the output: int a = 4, b = 7; System.out.println((a < b) + " " + (a == b - 3) + " " + (a > 2 && b < 5) + " " + (a > 2 || b < 5) + " " + !(a != 4)); (3 marks)

    Hint

    Evaluate each.

    Answer

    true true false true true

  3. Q3 · 4 marks · Short answerHarder board level

    Write a Java expression to compute the distance between points (1, 2) and (4, 6) using Math methods, the cube root of 64 plus the floor of 7.9, and give the values. (4 marks)

    Hint

    sqrt(9 + 16).

    Answer

    Math.sqrt(Math.pow(4 - 1, 2) + Math.pow(6 - 2, 2)) = sqrt(25) = 5.0. Math.cbrt(64) + Math.floor(7.9) = 4.0 + 7.0 = 11.0.

  4. Q4 · 3 marks · Short answerHarder board level

    Trace: Student x = new Student(); x.m = 50; Student y = x; y.m += 20; Student z = new Student(); z.m = 70; System.out.println(x.m + " " + y.m + " " + z.m + " " + (x == y) + " " + (x.m == z.m)); (3 marks)

    Hint

    x and y are one object.

    Answer

    x.m = y.m = 70; z.m = 70. Output: 70 70 70 true true (the two comparisons compare a reference and a value respectively).

  5. Q5 · 3 marks · Short answerHOTS / competency

    A program has: if (n != 0 & total / n > 10) and crashes when n is 0. Explain, correct the line and write an equivalent safe condition using a ternary expression for the average (average = total / n if n != 0, else 0). (3 marks)

    Hint

    & does not short-circuit.

    Answer

    The single & evaluates both sides, so total / n with n = 0 throws ArithmeticException. Use &&: if (n != 0 && total / n > 10). The average: int avg = (n != 0) ? total / n : 0;

Test your recall

Answer in your head or on paper first, then open the card. Pulling an answer out of memory makes it stick far better than re-reading.

  1. 1.&& vs &?Show answer

    && short-circuits; & does not.

  2. 2.Math.round(4.5)?Show answer

    5.

  3. 3.Two variables, one object means?Show answer

    They refer to the same object.

  4. 4.Compare string contents with?Show answer

    equals().

  5. 5.Math.floor(-4.2)?Show answer

    -5.0.

Relational and Logical Expressions, Object References and Library Functions: frequently asked questions

Is Math an object?

No, a class of static methods.

What does NaN mean?

Not a number.

What is null?

A reference with no object.

Does Math.random include 1?

No, it is less than 1.