• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Another Ques from abhilash's site

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question 27.
public class ADirtyOne
{
char a = '\u000A';
}
An attempt to compile the above class
1) will complete successfully.
2)will not compile as 0x000A is out of range for unicode charaters.
3)will complain about illegal character assignment
4) will compile but will cause a runtime error in accessing the variable.
Ans 3
Can someone please explain why 3?
Thanks in advance
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answer is 3 because
the literal you are assigning to your char has the form of a Unicode escape sequence
ie. \uxxxx
And these x's must be hexadecimal digits.
 
Chaitali Deshpande
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
greg
I think A is a hexadecimal digit
 
greg philpott
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry, you're right A is a Hexidecimal digit.
Here is the correct answer:
http://www.artima.com/java/answers/Nov2000/messages/66.html
basically the first thing the compiler does is convert all unicode escape characters first and as \u000a is the character for linefeed, your code turns into this:
char a = '
';
which gives you the compile error
That definitely is a dirty one!
[This message has been edited by greg philpott (edited February 22, 2001).]
 
It is an experimental device that will make my mind that most powerful force on earth! More powerful than this tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic