Sunday, July 21, 2024

Decrement Operators in Java

 Which symbol represents the decrement operator in Java?

a) ++

b) --

c) +=

d) *=


What does the post-decrement operator (i--) return in Java?

a) Decrements the value and returns the decremented value

b) Returns the current value and then decrements it

c) Multiplies the value of the variable by 2

d) Increases the value by 1


What is the result of the expression: int x = 7; int y = x--; in Java?

a) x = 6, y = 6

b) x = 7, y = 6

c) x = 6, y = 7

d) Compilation error


Which of the following is the pre-decrement operator in Java?

a) ++

b) --

c) +=

d) *=


What is the result of the expression: int a = 10; int b = --a; in Java?

a) a = 10, b = 10

b) a = 10, b = 9

c) a = 9, b = 10

d) a = 9, b = 9


Which operator is used to decrement the value of a variable by a specific number in Java?

a) ++

b) --

c) +=

d) *=


What is the value of 'num' after executing the code: int num = 15; num -= 4; in Java?

a) num = 15

b) num = 11

c) num = 4

d) num = 19


Which of the following statements is true about the decrement operator in Java?

a) It can be used with boolean variables.

b) It can only be used with integer variables.

c) It returns the current value and then decrements the variable.

d) It increases the value by 2.


What does the expression: int x = 5; x -= x--; evaluate to in Java?

a) x = 4

b) x = 5

c) x = 6

d) Compilation error


Which operator decrements the value of a variable by 1 in Java?

a) ++

b) --

c) +=

d) *=


Answers:


b) --

b) Returns the current value and then decrements it

b) x = 7, y = 6

b) --

b) a = 9, b = 9

c) +=

b) num = 11

b) It can only be used with integer variables.

d) Compilation error

b) --

No comments:

Post a Comment

git commands MCQ

 Here are some multiple-choice questions (MCQs) on Git commands relevant for Selenium: 1. Which Git command is used to clone a remote reposi...