1、下面代码将输出什么内容:(B false)
public class SystemUtil{
public static boolean isAdmin(String userId){
return userId.toLowerCase()=="admin";
}
public static void main(String[] args){
System.out.println(isAdmin("Admin"));
}
}
2、阅读如下代码。 请问,对语句行 test.hello(). 描述正确的有(A 能编译通过,并正确运行)
package NowCoder;
class Test {
public static void hello() {
System.out.println("hello");
}
}
public class MyApplication {
public static void main(String[] args) {
// TODO Auto-generated method stub
Test test=null;
test.hello();
}
}
A 能编译通过,并正确运行
B 因为使用了未初始化的变量,所以不能编译通过
C 以错误的方式访问了静态方法
D 能编译通过,但因变量为null,不能正常运行
3、. 在使用super和this关键字时,以下描述正确的是(A 在子类构造方法中使用super()显示调用父类的构造方法,super()必须写在子类构造方法的第一行,否则编译不通过)
A 在子类构造方法中使用super()显示调用父类的构造方法,super()必须写在子类构造方法的第一行,否则编译不通过
B super()和this()不一定要放在构造方法内第一行
C this()和super()可以同时出现在一个构造函数中
D this()和super()可以在static环境中使用,包括static方法和static语句块
4、如下代码的输出结果是什么?( D 编译失败)
public class Test {
public int aMethod(){
static int i = 0;
i++;
return i;
}