Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!

Ankur kothari

Ranch Hand
since Sep 06, 2009
Cows and Likes
Cows
0
In last 30 days
0
Total given
0
Likes
0
0
Total given
0
Given in last 30 days
0
Scavenger Hunt
Ranch Hand Scavenger Hunt
Greenhorn Scavenger Hunt

Recent posts by Ankur kothari

leave it...why dont either of you simply show me the calculation step by step...the answer is 16....maybe Ankit or Henry could explain properly
12 years ago
ok so correct me if am wrong

here x is 6;
x+=3 + ++x;

so Chandana according to you it would be x+=3+ 7; which evaluates to x+=10;

which is x=x+10;

which is x=10+7; right? or 10+6?
12 years ago
neha can you explain in detail?
12 years ago
so the output should be 17 right Chandana?
12 years ago
maybe its becasue the operands are evaluated from left to right....

i think this is x+= (AN_INT) + (++x).....first += is opened up soit is

its x=(x) + (AN_INT) + (++x)

this is simply so confusing
12 years ago
maybe its becasue its x*(7+5) becasue of that rule agian
12 years ago
then why is x*=7+5; not x=x*7+5; ?
12 years ago

here x is 84....according to K&B right of += is calculated first...

so minhaj i think your answer should be x+=3+7; which is x=7+10...17

then why 16? hmmmm
12 years ago
i think its because of ( x += AN_INT)+((++x))) becasue +comes first in the hierarchy
12 years ago
here char one =1; is converted to char one=(char)1 by the compiler because 1 is a compile time constant....

if you had final int i=1;
char one=i; even this would compile because i is a compile time constant here too

but this casting isnt done when a compile time constant isnt present
12 years ago
it wasnt a mock question....i was trying it myself....just thought of it
12 years ago
12 years ago

why does java Yipee does not give me null pointer exception? whereas

this does.....
12 years ago
its ok
12 years ago
dude the static method is inherited but does not follow overridden rules? like you cant refer to the subclass static method using superclass variable
12 years ago