面试题

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值