Prepare
Practice
Interview
Aptitude
Reasoning
English
GD
Placement papers
HR
Current affairs
Engineering
MCA
MBA
Online test
Login
Online Practice Test
>
Java
« Previous
Next »
If result = 2 + 3 * 5, what is the value and type of ‘result’ variable?
Options
- 17, byte
- 25, byte
- 17, int
- 25, int
CORRECT ANSWER : 17, int
Discussion Board
value and type of result variable
Hi Soujanya, the vlaue comes to 17int only and not 17byte because * is having higher precedence then + and after adding the value is no more byte but its changed to int after calculations.
Ankit 04-15-2015 09:35 PM
Precedence Operator
Java follows well defined rules for specifying the order in which the operators functions or it is evaluated in an expression. For example, multiplication and division have a higher precedence than addition and subtraction.
When two operators share an operand the operator with the higher precedence gets the preference. For example, 2 + 3 * 3 is treated as 2 + (3 * 5) since multiplication has a higher precedence than addition.
So according to this it turns out to be 15 as it is not having any decimal value then it is denoted by an integer which contains positive whole numbers.
Rohit Sharma 07-28-2014 03:28 AM
operator
As first preferance goes to higher precedance operators(like first division then multiplication on the basis of their first occurance),3*5 get calculated first =15 after that 2 is added =17 so result is 17
& in java default datatype of Integer type values is "int"
Rahul 02-5-2014 03:32 PM
value and type of result variable
Can you please explain in detail, on what basis value of variable "result" will 17,int
Soujanya D 12-13-2013 10:28 AM
« Previous
Next »
Write your comments
Enter the code shown above:
(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)
Related Content
Java Beginner (11)
Java (39)
Java (40)
Java (22)
Java (30)
Java (25)
Java (20)
Java (20)
Core Java (20)
Core Java (10)
Core Java (72)
EJB (20)
JDBC (20)
Applet (20)
Struts (21)
Servlets (20)
Java Web Services (20)
Javascript (40)
J2EE (10)
jQuery (46)
Advertisement
▲