Operators in java Relational Operators Question #20139
Single Choice Easy

QIf p is 10 and q is 10, what is the result of the expression p == q using the equality operator in Java?

ID: #20139 Relational Operators 106 views
Question Info
#20139Q ID
EasyDifficulty
Relational OperatorsTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • A true
  • B false
  • C 10
  • D 20
Correct Answer

Explanation

If p is 10 and q is 10, the result of the expression p == q using the equality operator (==) in Java would be true. The equality operator checks if the values on both sides are equal, and in this case, both p and q have the value of 10.

Here's a simple example:


public class EqualityOperatorExample {
    public static void main(String[] args) {
        // Example values
        int p = 10;
        int q = 10;

        // Check if p is equal to q
        boolean result = p == q;

        // Print the result
        System.out.println("Is p equal to q? " + result);
    }
}

In this case, the output will be:


Is p equal to q? true

Share This Question

Challenge a friend or share with your study group.