Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

An interview question I faced recently

 
arulk pillai
Author
Ranch Hand
Posts: 3387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What gets printed for the following code snippet?




 
Pushkar Choudhary
Rancher
Posts: 425
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just checked in Eclipse and Java 6, got the output: 65535

Still trying to figure it out.
 
arulk pillai
Author
Ranch Hand
Posts: 3387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pushkar Choudhary wrote:Just checked in Eclipse and Java 6, got the output: 65535

Still trying to figure it out.



Start with, -1 in binary is represented as all 1's.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A bad question. Whether you get the answer right or wrong proves nothing.

I can understand why the answer is what it is, but the question is a waste of time.
 
arulk pillai
Author
Ranch Hand
Posts: 3387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will have to admit that there were other good questions. The interviewer clearly indicated that it was an optional question to ascertain how technical I was. He was also more interested in the approach.
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A poor question in my opinion. Not sure how it demonstrates how "technical" a person is. If the question was about recitation of numeric casting rules it might make more sense. But to ask someone what will get "printed" is a bit looney ... and a waste of time.
 
Ninad Kulkarni
Ranch Hand
Posts: 802
Hibernate Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Refer this also Java Puzzler book have explaination about it.

According to my way of thinking the process is as follows.


first step is narrowing primitive conversions
second step + third step is widening & then narrowing primitive conversions
fourth step is widening primitive conversions
 
Luke Kolin
Ranch Hand
Posts: 343
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James Clarks wrote:A poor question in my opinion. Not sure how it demonstrates how "technical" a person is.


Agreed. Obscure Java trivia questions (unless one is implementing a JVM themselves) speak far more about the interviewer than the candidate.

Cheers!

Luke
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ninad Kulkarni wrote:Refer this also Java Puzzler book have explaination about it.

According to my way of thinking the process is as follows.


first step is narrowing primitive conversions
second step + third step is widening & then narrowing primitive conversions
fourth step is widening primitive conversions


If it was stolen from the java puzzler book, thats even worse
 
Ninad Kulkarni
Ranch Hand
Posts: 802
Hibernate Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Deepak
If it was stolen from the java puzzler book, thats even worse


All credit goes to authors of the Java Puzzlers book for this question already in java puzzle list in their book.
I given example of binary numbers to understand multiple cast process easily in the given question by using JLS3.0.
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ninad, I was not referring to you in my last post, I was referring to the person who took the interview. Just wanted to clarify that
 
Ninad Kulkarni
Ranch Hand
Posts: 802
Hibernate Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Deepak for clarification. Now I got your point.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic