037--常见面试题翻车合集

VIP免费
2024-12-11 1 0 22.42KB 9 页 5.9玖币
侵权投诉
常见面试题翻车合集
1.去掉 main 方法的 stac 修饰符,程序会怎样?
A:程序无法编译
B:程序正常编译,正常运行
C:程序正常编译,正常运行一下马上退出
D:程序正常编译,运行时报错
答:D
题目解析:运行时异常如下:
错误: main 方法不是类 xxx 中的 stac, 请将 main 方法定义为:
public stac void main(String[] args)
2.以下程序运行的结果是?
public class TestClass {
public static void main(String[] args) {
System.out.println(getLength());
}
int getLength() {
private String s = "xyz";
int result = s.length();
return result;
}
}
A3
B2
C4
D:程序无法编译
答:D
题目解析:成员变量 s 不能使用任何修饰符(private/protected/public)修饰,否则编译
会报错。
3.以下程序有几处错误?
abstract class myAbstractClass
private abstract String method(){};
}
A1
B2
C3
D4
答:C
题目解析:类少一个 {”类开始标签、抽象方法不能包含方法体、抽象方法访问修饰符不
能为 private ,因此总共有 3 处错误。
4.以下程序执行的结果是?
class A {
public static int x;
static {
x = B.y + 1;
}
}
public class B {
public static int y = A.x + 1;
public static void main(String[] args) {
System.out.println(String.format("x=%d,y=%d", A.x, B.y));
}
}
A:程序无法编译
B:程序正常编译,运行报错
Cx=1,y=2
Dx=0,y=1
答:C
5.switch 语法可以配合 return 一起使用吗?return break switch 使用上有何不同?
答:switch 可以配合 return 一起使用。return break 的区别在于 switch 结束之后的代
码,比如以下代码:
String getColor(String color) {
switch (color) {
case "red":
return "";
case "blue":
return "";
}
return "未知";
}
String getColor(String color) {
String result = "未知";
摘要:

常见面试题翻车合集1.去掉main方法的static修饰符,程序会怎样?A:程序无法编译B:程序正常编译,正常运行C:程序正常编译,正常运行一下马上退出D:程序正常编译,运行时报错答:D题目解析:运行时异常如下:错误:main方法不是类xxx中的static,请将main方法定义为:publicstaticvoidmain(String[]args)2.以下程序运行的结果是?publicclassTestClass{publicstaticvoidmain(String[]args){System.out.println(getLength());}intgetLength(){private...

展开>> 收起<<
037--常见面试题翻车合集.docx

共9页,预览2页

还剩页未读, 继续阅读

声明:本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。玖贝云文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知玖贝云文库,我们立即给予删除!
分类:计算机 价格:5.9玖币 属性:9 页 大小:22.42KB 格式:DOCX 时间:2024-12-11

开通VIP享超值会员特权

  • 多端同步记录
  • 高速下载文档
  • 免费文档工具
  • 分享文档赚钱
  • 每日登录抽奖
  • 优质衍生服务
/ 9
客服
关注