Thimal Deemantha

Greenhorn
+ Follow
since Nov 02, 2012
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Thimal Deemantha


Why the output is
A()
B()
A()
B(int)
A()
B(int,int)

I expected
A()
B()
A(int)
B(int)
A(int,int)
B(int,int)
11 years ago

Jesper de Jong wrote:Because the float and double data types are not infinitely precise; you can get rounding errors when you start doing calculations with them.



THANK YOU
11 years ago



Why the output is 3.2300000190734863
except 3.23
11 years ago

yamuna dulanajani wrote:
this can compile ,but

this gives a compile error ,
WHY?




The difference is that in the first case x is a compile time constant. i.e. the compiler knows that x will always have value 101, and by extension it knows that the if-condition will always be true and y will always be initialized to value -1. That's why it's legal to use y in the System.out.println() call: the compiler knows it was initialized to a value. In the other code sample x isn't a compile time constant and all the implications that held up in the first code sample don't. This leads the compiler to complain about the use of y, because it can't figure out whether or not it was initialized. At runtime, this is clearly the case, but the compiler just isn't smart enough to pick up on that.

got it from Jelle Klap
11 years ago

Jelle Klap wrote:Yeah, that's what I figured. The difference is that in the first case x is a compile time constant. i.e. the compiler knows that x will always have value 101, and by extension it knows that the if-condition will always be true and y will always be initialized to value -1. That's why it's legal to use y in the System.out.println() call: the compiler knows it was initialized to a value. In the other code sample x isn't a compile time constant and all the implications that held up in the first code sample don't. This leads the compiler to complain about the use of y, because it can't figure out whether or not it was initialized. At runtime, this is clearly the case, but the compiler just isn't smart enough to pick up on that.



THANK YOU
11 years ago



AND


11 years ago
No the 2nd could not compile
11 years ago
why the 2nd 1 gives compile error
11 years ago
what is the difference of


and

11 years ago