教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 文库大全 > 资格考试 >

4_JAVA+Oracle面试题(有答案)

来源:网络收集 时间:2025-10-06
导读: 有用的面试题 基础测试题 卷面上不能出现任何的涂写文字,所有的答案要求写在答题纸上,考卷不得带走。 选择题 1、 What will happen when you attempt to compile and run the following code? (D) public class Static { static { int x = 5; // 在stati

有用的面试题

基础测试题
卷面上不能出现任何的涂写文字,所有的答案要求写在答题纸上,考卷不得带走。
选择题
1、 What will happen when you attempt to compile and run the following code? (D)
public class Static {
static {
int x = 5; // 在static内有效
}
static int x, y; // 初始化为0
public static void main(String args[]) {
x--; // -1
myMethod();
System.out.println(x + y + ++x);
}
public static void myMethod() {
y = x++ + ++x; // y=-1+1 x=1
}
}
A.compiletime errorB.prints: 1C.prints: 2D、prints: 3E、prints: 7F、prints: 8
将以上的程序分步进行执行:
1、static int x, y;?x = 0 ;y = 0 ;
2、x--;?x = -1 ;y = 0 ;
3、y = x++ + ++x;?x = 1 ;y = 0 ;
4、System.out.println(x + y + ++x);?3
2、Given the following code, what will be the output? (A)
class Value {
public int i = 15;
}
public class Test {
public static void main(String argv[]) {
Test t = new Test();
t.first();
}
public void first() {
int i = 5;
Value v = new Value();
v.i = 25;
second(v, i);
System.out.println(v.i);
}
public void second(Value v, int i) {
i = 0;
v.i = 20;
Value val = new Value();
v = val;
System.out.println(v.i + " " + i);
}
}
A、15 0 20B、15 0 15C、20 0 20D、0 15 20

3、What will happen when you attempt to compile and run the following code? (A)
class MyParent {
int x, y;
MyParent(int x, int y) {
this.x = x;
this.y = y;
}
public int addMe(int x, int y) {
return this.x + x + y + this.y;
}
public int addMe(MyParent myPar) {
return addMe(myPar.x, myPar.y);
}
}
class MyChild extends MyParent {
int z;
MyChild(int x, int y, int z) {
super(x, y);
this.z = z;
}
public int addMe(int x, int y, int z) {
return this.x + x + this.y + y + this.z + z;
}
public int addMe(MyChild myChi) {
return addMe(myChi.x, myChi.y, myChi.z);
}
public int addMe(int x, int y) {
return this.x + x + this.y + y;
}
}
public class MySomeOne {
public static void main(String args[]) {
MyChild myChi = new MyChild(10, 20, 30);
MyParent myPar = new MyParent(10, 20);
int x = myChi.addMe(10, 20, 30);
int y = myChi.addMe(myChi);
int z = myPar.addMe(myPar);
System.out.println(x + y + z);
}
}
A、300B、240C、120D、180E、compile errorF、none of the above
class MyParent {
int x, y;
MyParent(int x, int y) {// 1020
this.x = x;
this.y = y;
}
public int addMe(int x, int y) {
return this.x + x + y + this.y;
}
public int addMe(MyParent myPar) {
return addMe(myPar.x, myPar.y);
}
}
class MyChild extends MyParent {
int z;
MyChild(int x, int y, int z) {// 102030
super(x, y);
this.z = z;
}
public int addMe(int x, int y,
int z) {
return this.x + x + this.y + y + this.z + z;
//101020203030-->120 + 120
}
public int addMe(MyChild myChi) {
retur

有用的面试题

n addMe(myChi.x, myChi.y, myChi.z);
}
public int addMe(int x, int y) {
return this.x + x + this.y + y;
}
}
public class MySomeOne {
public static void main(String args[]) {
MyChild myChi = new MyChild(10, 20, 30);
MyParent myPar = new MyParent(10, 20);
int x = myChi.addMe(10, 20, 30);// 120
int y = myChi.addMe(myChi);// 120
int z = myPar.addMe(myPar);// 60
System.out.println(x + y + z);
}
}
4、What will happen when you attempt to compile and run the following code? (E)
interface MyInterface {
}
public class MyInstanceTest implements MyInterface {
static String s;
public static void main(String args[]) {
MyInstanceTest t = new MyInstanceTest();
if (t instanceof MyInterface) {
System.out.println("I am true interface");
} else {
System.out.println("I am false interface");
}
if (s instanceof String) {
System.out.println("I am true String");
} else {
System.out.println("I am false String");
}
}
}
A、compile time error
B、runtime error
C、prints: “I am true interface” followed by “I am true String”
D、prints: “I am false interface” followed by “I am false String”
E、prints: “I am true interface” followed by “I am false String”
F、prints: “I am false interface” followed by “I am true String”
只有当一个对象实例化之后才有可能知道其具体的类型。
5、What results from attempting to compile and run the following code? (D)
public class Ternary {
public static void main(String args[]) {
int a = 5;
System.out.println("Value is - " + ((a < 5) ? 9.0 : 9)); ? 数据类型的自动转换 9.0
}
}
A、print:Value is -9B、print:Value is -5C、Compilation errorD、None of these
6、What will be the result of executing the following code? (D)
public static void main(String args[]) {
char digit = 'a';
for (int i = 0; i < 10; i++) {
switch (digit) {
case 'x': {
int j = 0;
System.out.println(j);
}
default: {
int j = 100;
System.out.println(j);
}
}
}
int i = j;
System.out.println(i);
}
A、100 will be printed 11 times.
B、100 will be printed 10 times and then there will be a runtime exception
C、The code will not compile because the variable i cannot be declared twice within the mani() method.
D、The code will not compile because the variable j cannot be declared twice within the switch statement.
E、None of these.
7、Which of the following collection classes from java.util package are Thread safe? (D)
A、VectorB、A …… 此处隐藏:4482字,全部文档内容请下载后查看。喜欢就下载吧 ……

4_JAVA+Oracle面试题(有答案).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wenku/107400.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)