• 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

character literal doubt

 
Ranch Hand
Posts: 274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For the following 2 codes:

*********code-1*************
public class ADirtyOne
{
//char a = '\u000A';
}
An attempt to compile the above class
1. will complete successfully.
2. will compile sucessfully but with a warning message.
3. will not compile - complains on an invalid expression.
Ans: 3 �unclosed character literal�

*********code-2*************
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 �illegal line end in character literal� WHY?


Doubt: I couldn't find any reason for the compilation to fail.

pls help
regards,
gitesh
[ August 28, 2007: Message edited by: Gitesh Ramchandani ]
 
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The compilation will fail because:

Using the Unicode escape characters \u000A for newline and \u000D for return in a String or comment produces a compile-error as they are interpreted, literally, as 'end-of-line'.

Always use the special characters '\n' or '\r'



Language Fundamentals - Character Literals
 
Gitesh Ramchandani
Ranch Hand
Posts: 274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Collins.

The source of questions,

AngelFire/Abhilash Q27 & 28
 
Now I am super curious what sports would be like if we allowed drugs and tiny ads.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic