1.public class Base {
static String s;
public static void main(String[] args) {
System.out.println("s="+s);
String e=s.toString();
System.out.println(e);
}
}
代码能够编译,打印出"s=null"
但是当调用toString()时抛出NullPointerException异常
2.
y=x++ + ++x;可以这样写,但是五个加号不要连着写。
3.boolean默认为false.
4.String s="Example";
s=s+10;
System.out.println(s);
结果为:Example10;
5.NULL和sizeof都不是关键字。
6。resume()负责恢复通过调用suspend()方法而停止的线程。
7.线程是抢占式的。
8.public class Person {
private int a;
}
public class Teacher extends Person {
public static void main(String[] args) {
Person p = new Person();
int i=p.a;//编译器报错,Thefield person.ais not visible
Teacher t = new Teacher();
int y = t.b;//编译器不报错,能正常执行。
}
}
9.public class Base {
int w, x, y, z;
public Base(int a, int b) {
x = a;
y = b;
}
public Base(int a, int b, int c, int d) {
// Base(a,b)//编译器错误 the method Base(int,int) is undefined for the type Base
this(a, b);
w = c;
z = d;
}
}
10.
>>为有符号右移
>>>为无符号右移
11.字符(char)的整型表示范围为0-65535.
12.可以这样赋值,为正确的java表达式:
char c=74;
13.java语言不支持goto,它是作为保留字。
14.
incompatible(与某事物)不一致,不相配
public class Super {
public int getLength(){
return 4;
}
}
public class Sub extends Super {
public long getLength(){//编译器报错
//错误为:1.The return type is incompatible withSuper.getLength();
//2.Override Super.getLength
return 5;
}
public static void main(String[] args) {
Super sooper=new Super();
Super sub=new Sub();
System.out.println(sooper.getLength()+","+sub.getLength());
}
}
当Sub里方法名不和Super里的getLength()一样就能编译通过。
或
当把Super里的getLength()的返回类型也改为long就能编译通过。
I know,because the Compiler cannot distinguish the same method signatures.It
cannot decide the type of return value.