• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ID:3 SCJP Question of the day : Thursday June 10 2010

 
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What will be the output of this code:




You know the rules, let's see your answers


Ref to rules... https://coderanch.com/t/498524/java-programmer-SCJP/certification/ID-SCJP-day-Wednesday-June

[HENRY: Added Reference. Change title id as requested]
 
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dude please do follow the Rules....If possible
Use ID3 instead of ID2

I have already posted ID2.......... i mean before you posted it !!!

You can just change the ID number to 3 in subject line !!!

Thanks for encouraging the concept !!!

Cheers!!!
 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Compilation Error :- I think ^(XOR) can be applied to integers only ~~!!!
 
Martin Vanyavchich
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry about the ID, when I started to post, your thread wasn't up yet. I will try to change it

... and your answer is correct, while the explanation isn't . The '^' XOR can be applied to booleans.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please leave the name out of the subject - it's long enough as it is. What's more, the name is visible wherever the topic title is visible, so it's redundant to begin with.
 
Martin Vanyavchich
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ulf is right. We could shorten the titles to just "ID# SCJP QOTD" since all othed info is visible wher you select the thread
 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:Please leave the name out of the subject - it's long enough as it is. What's more, the name is visible wherever the topic title is visible, so it's redundant to begin with.



Okay i agree, we would leave the name of an author from now onwards , but please do keep the date , inspite of being redundant, it looks attractive !!!

 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If XOR can be applied to booleans
then

Compilation error is on line 12

as (short+short) is solved to (int)
and then int cannot be applied to short again without the explicit cast.

So we could do the following :-

 
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code doesn't compile. But if you'd cast the result of the addition / subtraction to short it would be '100'...
 
Martin Vanyavchich
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sahil and Peter got it right! I'll try to make it more of a challenge the next time
 
Ranch Hand
Posts: 384
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I agree with Sahil because ... the auto conversion mechanism of java converts short to int when compiling so we need to re cast the same to short .

@sahil ... XOR can be applied to boolean values as well
 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Lalit , i remember it now !!!

 
Lalit Mehra
Ranch Hand
Posts: 384
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Sahil --> your welcome bro
 
reply
    Bookmark Topic Watch Topic
  • New Topic