/* * To change this template, choose Tools | Templates * and open the template in the editor. */package exp1;/** * * @author szhu5 */ public class NewClass { static char f= '\65'; public void a(){ //static char f= '\65'; System.out.println(f); //这么写为什么不报错啊 } }单从你说的那句上没有任何语法或逻辑错误,当然不报错,但static数据成员不能写在方法里面,只能写在类里
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/package exp1;/**
*
* @author szhu5
*/
public class NewClass {
static char f= '\65';
public void a(){
//static char f= '\65';
System.out.println(f);
//这么写为什么不报错啊
}
}单从你说的那句上没有任何语法或逻辑错误,当然不报错,但static数据成员不能写在方法里面,只能写在类里
static char f= '\67'; 只要这个值是'\0'-'\67'之间就不会错,
其它就会错。
定义 char f = '\65' 时,这里的'\65'是八进制的数字表示,换算成十进制就是53,
所以输出的时候,就是ASCII码里面 53 对应的字符:5因为是八进制表示的字符编码,所以也就出现了6楼所说的“有些值会错”。
http://blueram.javaeye.com/blog/251839
\[0-7][0-7]
\[0-3][0-7][0-7]即从 \0 到 \377 表示 \u0000~\u00ff 的字符。
http://java.sun.com/docs/books/jls/second_edition/html/lexical.doc.html#101089