File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question on unicode

 
Abacus White
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class JSC201 {
static byte m1() {
final char c = '\u0001';
return c; // 1
}
static byte m3(final char c) {return c;} // 2
public static void main(String[] args) {
char c = '\u0003';
System.out.print(""+m1()+m3(c));
}}

What is the result of attempting to compile and run the program?
a. Prints: 13
b. Prints: 4
c. Compile-time error at 1
d. Compile-time error at 2
e. Run-time error
f. None of the above
 
Corey McGlone
Ranch Hand
Posts: 3271
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what's your question? I assume you're quite capable of compiling and executing yourself, so what are you confused about?
 
Abacus White
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
f.java: In class `f':
f.java: In method `f.m1()':
f.java:33665: warning: Constant expression `0xfc00000003' too wide for narrowing primitive conversion to `byte'.
<<file too short - unexpected EOF>>


This is the outcome.I would like to know as to why this occured.
 
Corey McGlone
Ranch Hand
Posts: 3271
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmmm...that is not the output I received. When trying to compile that, I got this:



That error makes perfect sense as you can't implictly cast a char to a byte as going from a char to a byte is a narrowing conversion.

I'm not sure why you're getting the error you are. What version of Java are you comiling on?
 
Abacus White
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i'm using j2sdk1.4.1_01
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic