- 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.
- Java Questions Also
Java MCQ Questions and Answers on Arithmetic Operators 1
Study and learn Java MCQ questions and answers on Arithmetic Operators and their priorities. Attend job interviews easily with these Multiple Choice Questions.
Go through Java Theory Notes on Arithmetic Operators before studying questions.
Numbers are treated as int type by default. So an int value cannot be assigned to a short variable. You have to type cast the whole expression.
Compound assignment operators automatically convert the expression value to the left-hand side data type.
op++, op-- have more priority than --op, ++op.
All are having equal priority.
Again between Prefix and Post operators, Postfix operators have higher priority.
* has higher priority than +. So, Multiplication operation is performed first.
/ and * have equal priority. So associativity of Left to Right is used. Remember that 3/2 is 1 not 1.5 as both operands are integers.
At time of evaluating a++ == --b, a(5)is compared with --b(6-1). So, "if" condition passes. If you check a value after the ELSE block, it will be a+1 i.e 6.
After the ELSE block, b will be b+1 i.e 6
The prefix is incremented or decremented immediately . Postfix incremented or decremented on the next line/statement .
Java Typecasting MCQ Questions
Java MCQs on Relational Operators 1
Arithmetic and Assignment Operators Explained in Java
We promise these Arithmetic and Assignment Operators are more fun than the ones you used in Algebra II.
Arithmetic operators allow you to perform algebraic arithmetic in programming. That is, they enable you to add, subtract, divide and multiply numbers.
This article will also cover assignment operators. These enable you to give (assign) a certain value to a variable.
This tutorial is not just for Java programmers. Many other programming languages like C and Python use these same operators. Therefore, you can easily transfer and apply the knowledge you gain here.
Arithmetic Operators
There are 5 arithmetic operators in Java—the table below summarizes them.
The symbols ( + , - , / ) should seem familiar. That's because they're the same as those typically used in algebra.
It's important to take note that the division operator ( / ) refers to integer division here. That is, 19/5 will evaluate to 3 . Any fractional part that results from this computation is truncated.
Related: What Is a Constructor in Java and How Do You Use It?
You should have also noticed that the Java operator for multiplication is an asterisk ( * ) and not the usual multiplication symbol ( × ).
To get the modulus of two integers, Java uses the % symbol. The example given in the table is similar to the algebraic expression: y mod 3 . The % operator gives the remainder after y is divided by 3 . That is, 19%5 will evaluate to 4 .
It's good practice to use parentheses for grouping subexpressions. This eases readability and helps to avoid logic and syntax errors.
When you have multiple arithmetic operators in one expression, Java uses the rules of operator precedence to determine which subexpressions to evaluate first.
The table below categorizes the levels of operator precedence.
The operators ( * , / , % ) have the highest level of precedence, then followed by ( + , - ) and finally ( = ). The operators ( * , / , % ), and ( + , - ) all associate from left to right. This simply means that their evaluation begins from the leftmost operator.
The third operator ( = ) associates from right to left. So if have x=3 , that means 3 is assigned to x , and not x is assigned to 3.
Assignment Operators
The assignment operator ( = ) assigns a value to a variable.
The above expression adds 7 to y and then assigns the final result to y . If you're new to programming, this expression might seem a little weird. This shouldn't bother you as the compiler will understand what you're trying to do.
Compound Assignment
You can simplify the way you express an assignment by using a compound assignment operator.
In the previous example, we could've simply written:
See the table below on how you can use compound assignment operators.
Increment & Decrement Operators
If you have the compound assignment +=1 , you can simply write it as ++ . This is known as the "increment operator". Similarly, the decrement operator is -- .
Related: How to Write a for Loop in Java
When used before the operand, the increment and decrement operators are known as "prefix operators". And when used after the operand, they're called "postfix operators".
With prefix, the variable being operated on is first modified and then used while with postfix, the initial value before modification is used.
Generally, both postfix and prefix operators yield the same answer. It's only when dealing with large expressions that the answer may change.
Make Operators Work For You
It's important to note that increment and decrement operators only act on variables (e.g. x++ ) and not direct values (but not 5++ ). You should also not leave any whitespace while using increment and decrement operators, unlike with the operators before that. Doing so will give a compile-time error.
Always use parentheses when possible to logically group expressions. This will avoid unnecessary logic errors.
With these operators under your belt, understanding how to use access modifiers in Java will be a piece of cake.
The Java Tutorials have been written for JDK 8. Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available. See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases. See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.
Assignment, Arithmetic, and Unary Operators
The simple assignment operator.
One of the most common operators that you'll encounter is the simple assignment operator " = ". You saw this operator in the Bicycle class; it assigns the value on its right to the operand on its left:
This operator can also be used on objects to assign object references , as discussed in Creating Objects .
The Arithmetic Operators
The Java programming language provides operators that perform addition, subtraction, multiplication, and division. There's a good chance you'll recognize them by their counterparts in basic mathematics. The only symbol that might look new to you is " % ", which divides one operand by another and returns the remainder as its result.
The following program, ArithmeticDemo , tests the arithmetic operators.
This program prints the following:
You can also combine the arithmetic operators with the simple assignment operator to create compound assignments . For example, x+=1; and x=x+1; both increment the value of x by 1.
The + operator can also be used for concatenating (joining) two strings together, as shown in the following ConcatDemo program:
By the end of this program, the variable thirdString contains "This is a concatenated string.", which gets printed to standard output.
The Unary Operators
The unary operators require only one operand; they perform various operations such as incrementing/decrementing a value by one, negating an expression, or inverting the value of a boolean.
The following program, UnaryDemo , tests the unary operators:
The increment/decrement operators can be applied before (prefix) or after (postfix) the operand. The code result++; and ++result; will both end in result being incremented by one. The only difference is that the prefix version ( ++result ) evaluates to the incremented value, whereas the postfix version ( result++ ) evaluates to the original value. If you are just performing a simple increment/decrement, it doesn't really matter which version you choose. But if you use this operator in part of a larger expression, the one that you choose may make a significant difference.
The following program, PrePostDemo , illustrates the prefix/postfix unary increment operator:
About Oracle | Contact Us | Legal Notices | Terms of Use | Your Privacy Rights
Copyright © 1995, 2022 Oracle and/or its affiliates. All rights reserved.
- Java Arrays
- Java Strings
- Java Collection
- Java 8 Tutorial
- Java Multithreading
- Java Exception Handling
- Java Programs
- Java Project
- Java Collections Interview
- Java Interview Questions
- Spring Boot
- Java Tutorial
Overview of Java
- Introduction to Java
- The Complete History of Java Programming Language
- C++ vs Java vs Python
- How to Download and Install Java for 64 bit machine?
- Setting up the environment in Java
- How to Download and Install Eclipse on Windows?
- JDK in Java
- How JVM Works - JVM Architecture?
- Differences between JDK, JRE and JVM
- Just In Time Compiler
- Difference between JIT and JVM in Java
- Difference between Byte Code and Machine Code
- How is Java platform independent?
Basics of Java
- Java Basic Syntax
- Java Hello World Program
- Java Data Types
- Primitive data type vs. Object data type in Java with Examples
- Java Identifiers
Operators in Java
- Java Variables
- Scope of Variables In Java
Wrapper Classes in Java
Input/output in java.
- How to Take Input From User in Java?
- Scanner Class in Java
- Java.io.BufferedReader Class in Java
- Difference Between Scanner and BufferedReader Class in Java
- Ways to read input from console in Java
- System.out.println in Java
- Difference between print() and println() in Java
- Formatted Output in Java using printf()
- Fast I/O in Java in Competitive Programming
Flow Control in Java
- Decision Making in Java (if, if-else, switch, break, continue, jump)
- Java if statement with Examples
- Java if-else
- Java if-else-if ladder with Examples
- Loops in Java
- For Loop in Java
- Java while loop with Examples
- Java do-while loop with Examples
- For-each loop in Java
- Continue Statement in Java
- Break statement in Java
- Usage of Break keyword in Java
- return keyword in Java
- Java Arithmetic Operators with Examples
- Java Unary Operator with Examples
Java Assignment Operators with Examples
- Java Relational Operators with Examples
- Java Logical Operators with Examples
- Java Ternary Operator with Examples
- Bitwise Operators in Java
- Strings in Java
- String class in Java
- Java.lang.String class in Java | Set 2
- Why Java Strings are Immutable?
- StringBuffer class in Java
- StringBuilder Class in Java with Examples
- String vs StringBuilder vs StringBuffer in Java
- StringTokenizer Class in Java
- StringTokenizer Methods in Java with Examples | Set 2
- StringJoiner Class in Java
- Arrays in Java
- Arrays class in Java
- Multidimensional Arrays in Java
- Different Ways To Declare And Initialize 2-D Array in Java
- Jagged Array in Java
- Final Arrays in Java
- Reflection Array Class in Java
- util.Arrays vs reflect.Array in Java with Examples
OOPS in Java
- Object Oriented Programming (OOPs) Concept in Java
- Why Java is not a purely Object-Oriented Language?
- Classes and Objects in Java
- Naming Conventions in Java
- Java Methods
Access Modifiers in Java
- Java Constructors
- Four Main Object Oriented Programming Concepts of Java
Inheritance in Java
Abstraction in java, encapsulation in java, polymorphism in java, interfaces in java.
- 'this' reference in Java
- Inheritance and Constructors in Java
- Java and Multiple Inheritance
- Interfaces and Inheritance in Java
- Association, Composition and Aggregation in Java
- Comparison of Inheritance in C++ and Java
- abstract keyword in java
- Abstract Class in Java
- Difference between Abstract Class and Interface in Java
- Control Abstraction in Java with Examples
- Difference Between Data Hiding and Abstraction in Java
- Difference between Abstraction and Encapsulation in Java with Examples
- Difference between Inheritance and Polymorphism
- Dynamic Method Dispatch or Runtime Polymorphism in Java
- Difference between Compile-time and Run-time Polymorphism in Java
Constructors in Java
- Copy Constructor in Java
- Constructor Overloading in Java
- Constructor Chaining In Java with Examples
- Private Constructors and Singleton Classes in Java
Methods in Java
- Static methods vs Instance methods in Java
- Abstract Method in Java with Examples
- Overriding in Java
- Method Overloading in Java
- Difference Between Method Overloading and Method Overriding in Java
- Differences between Interface and Class in Java
- Functional Interfaces in Java
- Nested Interface in Java
- Marker interface in Java
- Comparator Interface in Java with Examples
- Need of Wrapper Classes in Java
- Different Ways to Create the Instances of Wrapper Classes in Java
- Character Class in Java
- Java.Lang.Byte class in Java
- Java.Lang.Short class in Java
- Java.lang.Integer class in Java
- Java.Lang.Long class in Java
- Java.Lang.Float class in Java
- Java.Lang.Double Class in Java
- Java.lang.Boolean Class in Java
- Autoboxing and Unboxing in Java
- Type conversion in Java with Examples
Keywords in Java
- Java Keywords
- Important Keywords in Java
- Super Keyword in Java
- final Keyword in Java
- static Keyword in Java
- enum in Java
- transient keyword in Java
- volatile Keyword in Java
- final, finally and finalize in Java
- Public vs Protected vs Package vs Private Access Modifier in Java
- Access and Non Access Modifiers in Java
Memory Allocation in Java
- Java Memory Management
- How are Java objects stored in memory?
- Stack vs Heap Memory Allocation
- How many types of memory areas are allocated by JVM?
- Garbage Collection in Java
- Types of JVM Garbage Collectors in Java with implementation details
- Memory leaks in Java
- Java Virtual Machine (JVM) Stack Area
Classes of Java
- Understanding Classes and Objects in Java
- Singleton Method Design Pattern in Java
- Object Class in Java
- Inner Class in Java
- Throwable Class in Java with Examples
Packages in Java
- Packages In Java
- How to Create a Package in Java?
- Java.util Package in Java
- Java.lang package in Java
- Java.io Package in Java
- Java Collection Tutorial
Exception Handling in Java
- Exceptions in Java
- Types of Exception in Java with Examples
- Checked vs Unchecked Exceptions in Java
- Java Try Catch Block
- Flow control in try catch finally in Java
- throw and throws in Java
- User-defined Custom Exception in Java
- Chained Exceptions in Java
- Null Pointer Exception In Java
- Exception Handling with Method Overriding in Java
- Multithreading in Java
- Lifecycle and States of a Thread in Java
- Java Thread Priority in Multithreading
- Main thread in Java
- Java.lang.Thread Class in Java
- Runnable interface in Java
- Naming a thread and fetching name of current thread in Java
- What does start() function do in multithreading in Java?
- Difference between Thread.start() and Thread.run() in Java
- Thread.sleep() Method in Java With Examples
- Synchronization in Java
- Importance of Thread Synchronization in Java
- Method and Block Synchronization in Java
- Lock framework vs Thread synchronization in Java
- Difference Between Atomic, Volatile and Synchronized in Java
- Deadlock in Java Multithreading
- Deadlock Prevention And Avoidance
- Difference Between Lock and Monitor in Java Concurrency
- Reentrant Lock in Java
File Handling in Java
- Java.io.File Class in Java
- Java Program to Create a New File
- Different ways of Reading a text file in Java
- Java Program to Write into a File
- Delete a File Using Java
- File Permissions in Java
- FileWriter Class in Java
- Java.io.FileDescriptor in Java
- Java.io.RandomAccessFile Class Method | Set 1
- Regular Expressions in Java
- Regex Tutorial - How to write Regular Expressions?
- Matcher pattern() method in Java with Examples
- Pattern pattern() method in Java with Examples
- Quantifiers in Java
- java.lang.Character class methods | Set 1
- Java IO : Input-output in Java with Examples
- Java.io.Reader class in Java
- Java.io.Writer Class in Java
- Java.io.FileInputStream Class in Java
- FileOutputStream in Java
- Java.io.BufferedOutputStream class in Java
- Java Networking
- TCP/IP Model
- User Datagram Protocol (UDP)
- Differences between IPv4 and IPv6
- Difference between Connection-oriented and Connection-less Services
- Socket Programming in Java
- java.net.ServerSocket Class in Java
- URL Class in Java with Examples
JDBC - Java Database Connectivity
- Introduction to JDBC (Java Database Connectivity)
- JDBC Drivers
- Establishing JDBC Connection in Java
- Types of Statements in JDBC
- JDBC Tutorial
- Java 8 Features - Complete Tutorial
Operators constitute the basic building block of any programming language. Java too provides many types of operators which can be used according to the need to perform various calculations and functions, be it logical, arithmetic, relational, etc. They are classified based on the functionality they provide.
Types of Operators:
- Arithmetic Operators
- Unary Operators
- Assignment Operator
- Relational Operators
- Logical Operators
- Ternary Operator
- Bitwise Operators
- Shift Operators
This article explains all that one needs to know regarding Assignment Operators.
Assignment Operators
These operators are used to assign values to a variable. The left side operand of the assignment operator is a variable, and the right side operand of the assignment operator is a value. The value on the right side must be of the same data type of the operand on the left side. Otherwise, the compiler will raise an error. This means that the assignment operators have right to left associativity, i.e., the value given on the right-hand side of the operator is assigned to the variable on the left. Therefore, the right-hand side value must be declared before using it or should be a constant. The general format of the assignment operator is,
Types of Assignment Operators in Java
The Assignment Operator is generally of two types. They are:
1. Simple Assignment Operator: The Simple Assignment Operator is used with the “=” sign where the left side consists of the operand and the right side consists of a value. The value of the right side must be of the same data type that has been defined on the left side.
2. Compound Assignment Operator: The Compound Operator is used where +,-,*, and / is used along with the = operator.
Let’s look at each of the assignment operators and how they operate:
1. (=) operator:
This is the most straightforward assignment operator, which is used to assign the value on the right to the variable on the left. This is the basic definition of an assignment operator and how it functions.
Syntax:
Example:
2. (+=) operator:
This operator is a compound of ‘+’ and ‘=’ operators. It operates by adding the current value of the variable on the left to the value on the right and then assigning the result to the operand on the left.
Note: The compound assignment operator in Java performs implicit type casting. Let’s consider a scenario where x is an int variable with a value of 5. int x = 5; If you want to add the double value 4.5 to the integer variable x and print its value, there are two methods to achieve this: Method 1: x = x + 4.5 Method 2: x += 4.5 As per the previous example, you might think both of them are equal. But in reality, Method 1 will throw a runtime error stating the “i ncompatible types: possible lossy conversion from double to int “, Method 2 will run without any error and prints 9 as output.
Reason for the Above Calculation
Method 1 will result in a runtime error stating “incompatible types: possible lossy conversion from double to int.” The reason is that the addition of an int and a double results in a double value. Assigning this double value back to the int variable x requires an explicit type casting because it may result in a loss of precision. Without the explicit cast, the compiler throws an error. Method 2 will run without any error and print the value 9 as output. The compound assignment operator += performs an implicit type conversion, also known as an automatic narrowing primitive conversion from double to int . It is equivalent to x = (int) (x + 4.5) , where the result of the addition is explicitly cast to an int . The fractional part of the double value is truncated, and the resulting int value is assigned back to x . It is advisable to use Method 2 ( x += 4.5 ) to avoid runtime errors and to obtain the desired output.
Same automatic narrowing primitive conversion is applicable for other compound assignment operators as well, including -= , *= , /= , and %= .
3. (-=) operator:
This operator is a compound of ‘-‘ and ‘=’ operators. It operates by subtracting the variable’s value on the right from the current value of the variable on the left and then assigning the result to the operand on the left.
4. (*=) operator:
This operator is a compound of ‘*’ and ‘=’ operators. It operates by multiplying the current value of the variable on the left to the value on the right and then assigning the result to the operand on the left.
5. (/=) operator:
This operator is a compound of ‘/’ and ‘=’ operators. It operates by dividing the current value of the variable on the left by the value on the right and then assigning the quotient to the operand on the left.
6. (%=) operator:
This operator is a compound of ‘%’ and ‘=’ operators. It operates by dividing the current value of the variable on the left by the value on the right and then assigning the remainder to the operand on the left.
Please Login to comment...
Similar reads.
- Java-Operators
- How to Organize Your Digital Files with Cloud Storage and Automation
- 10 Best Blender Alternatives for 3D Modeling in 2024
- How to Transfer Photos From iPhone to iPhone
- What are Tiktok AI Avatars?
- 30 OOPs Interview Questions and Answers (2024)
Improve your Coding Skills with Practice
What kind of Experience do you want to share?
Java Tutorial
Control statements, java object class, java inheritance, java polymorphism, java abstraction, java encapsulation, java oops misc.
- Send your Feedback to [email protected]
Help Others, Please Share
Learn Latest Tutorials
Transact-SQL
Reinforcement Learning
R Programming
React Native
Python Design Patterns
Python Pillow
Python Turtle
Preparation
Verbal Ability
Interview Questions
Company Questions
Trending Technologies
Artificial Intelligence
Cloud Computing
Data Science
Machine Learning
B.Tech / MCA
Data Structures
Operating System
Computer Network
Compiler Design
Computer Organization
Discrete Mathematics
Ethical Hacking
Computer Graphics
Software Engineering
Web Technology
Cyber Security
C Programming
Control System
Data Mining
Data Warehouse
Java Guides
Search this blog.
Check out my 10+ Udemy bestseller courses and discount coupons: Udemy Courses - Ramesh Fadatare
Java Operators Quiz - MCQ - Multiple Choice Questions
In this blog post, we present a Java Operators quiz to test your knowledge and understanding of operators in the Java programming language.
Operators play a crucial role in performing various operations on data, including arithmetic, assignment, logical operators, comparison, and more. Let's dive into the quiz questions and see how well you can tackle these challenges!
Learn and Master Java Programming: Learn Java Programming with Examples
Check out 100+ quiz questions: 100+ Quiz Questions to Test Your Java, Spring Boot, Microservices, Hibernate, REST API Skills
The answer and explanation of each question have given at the end of this post.
1. Which operator is used for equality comparison in Java?
2. which operator is used for arithmetic addition in java , 3. what is the output of the following program, 4. which operator is used for performing logical and in java , 5. what is the output of the following program, 6. what is the output of the following program, 7. what is the output of the following program, 8. which operator is used to increment a variable by one in java , 9. which operator is used for performing string concatenation in java , answers and explanations.
Explanation:
The relational operator in Java is used to compare two values. The == operator is used to check if two values are equal or not.
The + operator is used for arithmetic addition in Java.
The postfix increment operator (x++) first assigns the value of x to y, and then increments the value of x. Therefore, the value of y is 10.
a) &&
The && operator is used for logical AND in Java.
The % operator is used for finding the remainder of the division operation. In this case, 5 divided by 2 leaves a remainder of 1.
a) x is greater
Related Quizzes:
Post a comment.
Leave Comment
My Top and Bestseller Udemy Courses
- Spring 6 and Spring Boot 3 for Beginners (Includes Projects)
- Building Real-Time REST APIs with Spring Boot
- Building Microservices with Spring Boot and Spring Cloud
- Full-Stack Java Development with Spring Boot 3 & React
- Testing Spring Boot Application with JUnit and Mockito
- Master Spring Data JPA with Hibernate
- Spring Boot Thymeleaf Real-Time Web Application - Blog App
Check out all my Udemy courses and updates: Udemy Courses - Ramesh Fadatare
Copyright © 2018 - 2025 Java Guides All rights reversed | Privacy Policy | Contact | About Me | YouTube | GitHub
Compound Assignment Operators
Source: (compoundassignment.java), related examples:.
Arithmetic Operators Compound Assignment Operators Concatenating Strings Conditional Operator Equality Operators Equality Reference Variables Equality and Relational Operators Increment Decrement Unary Operators Instanceof Comparison Logical Operators Logical Short Circuit Operator Precedence Examples Post Decrement Post Increment Pre Decrement Pre Increment Short Circuit Logical Operators Ternary Example
Java Examples | Operators | Compound Assignment Operators
All of the above
Posted under Operators and Control Statements Java Programming
Engage with the Community - Add Your Comment
Confused About the Answer? Ask for Details Here.
Know the Explanation? Add it Here.
Q. Choose the Compound Assignment Arithmetic Operators in Java below.
Similar questions, discover related mcqs.
Q. Which is the arithmetic operator in Java that gives the Remainder of Division?
View solution
Q. Arithmetic operators +, -, /, * and % have which Associativity?
Q. Between Postfix and Prefix arithmetic operators in Java, which operators have more priority?
Q. Among Postfix Decrement and Prefix Incrementoperators in Java, which operator has less priority?
Q. Increment and Decrement arithmetic operators in Java has which Associativity?
Q. Choose the correct statement about Java Operators +, -, *, / and %.
Q. Among the operator groups (++, --)and (+, -, *, /, %) in Java, which group has higher priority?
Q. Choose the correct statement about Java Prefix and Postfix operations.
Q. What is the other name for Relational Operators in Java?
Q. How many minimum number of operands are required to use Comparison operators in Java?
Q. What are the types of data that can be used along with Relational operators in Java?
Q. Choose the Conditional operators of Java listed below.
Q. Which operator group has higher priority between (>, >=, <, <=) and (==, !=)?
Q. What is the data type of output of any Comparison Operation in Java?
Q. Among Relational operators and Assignment operators, which operators have higher priority?
Q. What are the two possible Logical Operator types?
Q. Boolean logical operators in Java work with?
Q. Bitwise logical operators in Java work with?
Q. In general Bitwise logical operators are simply called?
Q. What is the input for Logical Operators?
Suggested Topics
Are you eager to expand your knowledge beyond Java Programming? We've curated a selection of related categories that you might find intriguing.
Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!
Data Structures and Algorithms
Journey through the fundamentals of Data Structures and Algorithms with our extensive...
Data Science
Discover the fascinating world of extracting insights from data with our Data Science...
Polish your web design skills with our CSS MCQs. Learn about selectors, properties,...
Management Information Systems
Discover how businesses leverage technology with our Management Information Systems...
Strengthen your web development skills with our JavaScript MCQs. Understand core...
Wireless and Mobile Communications
Get to grips with modern communication technologies with our Wireless and Mobile...
Operating System
Dive deep into the core of computers with our Operating System MCQs. Learn about...
Master the suite of productivity tools with our MS Office MCQs. From Word and Excel...
Systems Analysis and Design Methods
Get familiar with the process of designing and improving business systems with our...
Java Arithmetic Operators Compound Assignment Operators
Java language, package import, data structures, design patterns, regular expression, oca ocp exam 1, oca ocp exam 2, oca ocp exam 3, oca ocp exam 4, oca ocp exam 5, oca ocp exam 6, oca ocp exam 7, oca ocp exam 8, oca ocp exam 9, oca ocp exam 10, oca ocp exam 11, oca ocp exam 12, oca ocp exam 13, oca ocp exam 14, oca ocp exam 15, oca ocp exam 16, oca ocp exam 17, oca ocp exam 18, oca ocp exam 19, oca ocp exam 20, oca ocp exam 21, oca ocp exam 22, oca ocp exam 23, oca ocp exam 24, oca ocp exam 25, oca ocp exam 26, oca ocp exam 27, oca ocp exam 28, oca ocp exam 29, oca ocp exam 30, oca ocp exam 31, oca ocp exam 32, oca ocp exam 33, introduction.
Java Arithmetic Compound Assignment Operators can combine an arithmetic operation with an assignment.
For the following statement:
In Java, you can rewrite this statement as shown here:
This version uses the += compound assignment operator.
Both statements perform the same action: they increase the value of a by 4.
Here is another example,
which can be expressed as
In this case, the %= obtains the remainder of a /2 and puts that result back into a.
There are compound assignment operators for all of the arithmetic, binary operators.
Any statement of the form
can be rewritten as
The following code shows several op= assignments:
Home / Programming MCQs / JAVA MCQs / Question
Q. Choose the Compound Assignment Arithmetic Operators in Java below.
Correct answer: Option(D)
Share in MCQ Buddy Groups
No solution found for this question. Add Solution and get +2 points.
Discusssion
Login to discuss.
Related MCQs on JAVA
Which of those is synchronized and does not allow null elements?
Which Java method is used to get the version of running java VM?
What is the output for the below code ?
Which of these coding types is used for data type characters in Java?
The .dot operator connects the following two entities _____.
Which of the following is true about inheritance in Java. 1) In Java all classes inherit from the Object class directly or indirectly. The Object class is root of all classes. 2) Multiple inheritance is not allowed in Java. 3) Unlike C++, there is nothing like type of inheritance in Java where we can specify whether the inheritance is protected, public or private.
If you access an uninitialized local variable will result?
Identify the modifier which cannot be used for constructor.
Unlike C-Arrays, the Java-Arrays have ___.
What is the output of the below Java program?
IMAGES
VIDEO
COMMENTS
The following are all possible assignment operator in java: 1. += (compound addition assignment operator) 2. -= (compound subtraction assignment operator) 3. *= (compound multiplication assignment operator) 4. /= (compound division assignment operator) 5. %= (compound modulo assignment operator)
a) Assignment operators are more efficiently implemented by Java run-time system than their equivalent long forms. b) Assignment operators run faster than their equivalent long forms. c) Assignment operators can be used only with numeric and character data type. d) None of the mentioned. View Answer.
Compound Assignment Operators. An assignment operator is a binary operator that assigns the result of the right-hand side to the variable on the left-hand side. The simplest is the "=" assignment operator: int x = 5; This statement declares a new variable x, assigns x the value of 5 and returns 5. Compound Assignment Operators are a shorter ...
The compound assignment operator is the combination of more than one operator. It includes an assignment operator and arithmetic operator or bitwise operator. The specified operation is performed between the right operand and the left operand and the resultant assigned to the left operand. Generally, these operators are used to assign results ...
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. 1.
Operators in Java MCQ. Java is a popular programming language that is widely used for developing applications in various domains such as web development, mobile app development, and more. In Java, operators are used to perform various operations on variables and values.
Study and learn Java MCQ questions and answers on Arithmetic Operators and their priorities. Attend job interviews easily with these Multiple Choice Questions. Go through Java Theory Notes on Arithmetic Operators before studying questions.
Compound assignment operators in Java are shorthand notations that combine an arithmetic or bitwise operation with an assignment. They allow you to perform an operation on a variable's value and then assign the result back to the same variable in a single step.
Boolean operators are used to perform logical comparisons, and always result in one of two values: true or false. Following are the most commonly used Boolean operators : AND: Compares two values and returns true if they are both true. OR: Compares two values and returns true if either of the values are true. Negation: Flips the state of a value.
Assignment Operators The assignment operator (=) assigns a value to a variable. y = y+7; The above expression adds 7 to y and then assigns the final result to y. If you're new to programming, this expression might seem a little weird. This shouldn't bother you as the compiler will understand what you're trying to do. Compound Assignment
Java provides special operators that can be used to combine an arithmetic operation with an assignment. As you probably know, statements like the following are quite common in programming: a = a + 4; In Java, you can rewrite this statement as shown here: a += 4; This version uses the += compound assignment operator.
You can also combine the arithmetic operators with the simple assignment operator to create compound assignments. For example, x+=1; and x=x+1; both increment the value of x by 1. The + operator can also be used for concatenating (joining) two strings together, as shown in the following ConcatDemo program:
Example: Note: The compound assignment operator in Java performs implicit type casting. Let's consider a scenario where x is an int variable with a value of 5. int x = 5; If you want to add the double value 4.5 to the integer variable x and print its value, there are two methods to achieve this: Method 1: x = x + 4.5.
8. Operators for Compound Assignments. Compound assignment operators enable you to execute a computation and assign the result to a variable in a single statement by combining an arithmetic operator with an assignment operator. In Java, there are several varieties of compound assignment operators, including: +=: adds a value to a variable and ...
Learn about the Java Compound Assignment Operators. They are basically shorthand or shortcut operators for performing arithmetic and assigning a variable at ...
Java Compound Assignment Operators. In this chapter you will learn: ... Example - Arithmetic Compound Assignment Operators; Description. Statements like the following a = a + 4; can be rewritten as a += 4; Both statements perform the same action: they increase the value of a by 4. Syntax. Any statement of the form
The + operator is used for arithmetic addition in Java. Question 3. Answer: a) 10 Explanation: The postfix increment operator (x++) first assigns the value of x to y, and then increments the value of x. Therefore, the value of y is 10. Question 4. Answer: a) && Explanation: The && operator is used for logical AND in Java. Question 5. Answer: c ...
In Java, you can replace a += b with a = a + b.And that is very important.. Hence your expression is equivalent to. a = a + (a = a + b) + c. Note that this will be evaluated as a = Term1 + Term2 + Term3 and in the order left to right.. Term1 is 2.. Term2 is the only tricky one. It is 5 (and has the side-effect of increasing a to 5 but that gets clobbered by the eventual assignment).
Java source code. Java Examples: Operators - Compound Assignment Operators. javacodex.com. Java Examples. Compound Assignment Operators. Compound assignment operators provide a shorter syntax for assigning the result of an arithmetic or bitwise operator. They perform the operation on the two operands before assigning the result to the first ...
Choose the Compound Assignment Arithmetic Operators in Java below. +=, -= *=, /= %= All of the above. Java Programming Objective type Questions and Answers. Computer Science Edu ... Level up your coding skills with our Java Programming MCQs. From object-oriented...
I noticed in my benchmarks that arithmetic compound operators in Java always outperform the regular assignment: d0 *= d0; //faster //d0 = d0 * d0; //slower d0 += d0; //faster //d0 = d0 + d0; //slower Could someone please comment on the above observation and explain why it is the case.
Java Arithmetic Compound Assignment Operators can combine an arithmetic operation with an assignment. For the following statement: a = a + 4; In Java, you can rewrite this statement as shown here: a += 4; This version uses the += compound assignment operator. Both statements perform the same action: they increase the value of a by 4. ...
Related MCQs on JAVA . concurrentSkipListMap permits. What is the other name for a Question Mark - Colon (?:) operator in Java? Which one is commonly used to extend the applications hosted by web servers. Which of the following holds data retrieved from a database after you execute an SQLquery using Statement objects?