This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes java primitive problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "java primitive problem" Watch "java primitive problem" New topic
Author

java primitive problem

Mohit G Gupta
Ranch Hand

Joined: May 18, 2010
Posts: 634



output:
115
115
s
ssks

why is the second print statement displaying 115 ?
shouldn't be the output s as in case of third print statement.


OCPJP 6.0 93%
OCPJWCD 5.0 98%
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

The + before c in that expression represents the unary operator + which makes its operand c an int...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Abimaran Kugathasan
Ranch Hand

Joined: Nov 04, 2009
Posts: 2066

mohitkumar gupta wrote:

output:
115
115
s
ssks
why is the second print statement displaying 115 ?
shouldn't be the output s as in case of third print statement.


Numeric promotion with unary operators(+,-,and ~)

The evaluation of the expression +c will first promote the value c to int and then apply the operator + resulting in an int value. This will also apply to char, short, byte...


|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java primitive problem
 
Similar Threads
Intersting Question
String literal Pool doubt
Static blocks
String splitting
Array value