第一范文网 - 专业文章范例文档资料分享平台

Java基础面试题及答案

来源:用户分享 时间:2025/8/4 12:23:42 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

.

JAVA基础部分-选择题

(单选)1.在Java语言中,字符串“Java程序员”在内存中所占用的字节数是:()。

A.10 B.7 C.13 D.14

2. (单选)下列表达式中,可以得到精确结果的是()。

A.double d1 = 3.0 - 2.6; B.double d4 = 2.5 * 1.5; C.double d2 = 30/300; D.double d3 = 1/2 + 0.5;

3.(多选)所谓“水仙花”数是一个整数等于各位数字立方的和,例如:153 = 111+555+333,下面的程序用于输出2~1000内的水仙花数: for (int n = 2; n <= 1000; n++) { 空白处 if (s == n) { System.out.println(n); } } 下列选项中,空白处可以填入的代码是:()。 A.int s = 0, n1 = n; while (n1 > 0) { int t = n1 % 10; s += t * t * t; n1 /= 10; }

B.int s = 0, n1 = n; while (n1 > 0) { int t = n1 / 10; s+= t * t * t; n1 %= 10; } C.int s = 0; for(int n1 = n; n1>0; n1 /= 10) { int t = n1; s += t * t * t; } D.int s = 0; for(int n1 = n; n1>0; n1 %= 10) { int t = n1 / 10; s += t * t * t; }

4.下列语句序列执行后,k 的值是 ( )

.

.

int x=6, y=10, k=5; switch( x % y ) { case 0: k=x*y; case 6: k=x/y; case 12: k=x-y; default: k=x*y-x; } A.60 B.5 C.0 D.54

5.设 a = 8,则表达式 a >>> 2 的值是: (无符号右移动)( )

A.1 B.2 C.3 D.4

6.下列程序

class Test{ public static void main(String[] args){ doSomething(1); doSomething(1,2); } //insert code here } 在程序中插入下列哪一行代码可以编译通过: A static void doSomething(int[] args){} B static void doSomething(int... args){} C static coid doSomething(int...args,int x){}

.

.

D static void doSomething(int x,int...args){}

简答题

1.现有一个长度为20的数组,数组内的数字0-9之间的任意数字,统计出数组中每个元素出现的次数?

现有一个字符串\现统计出子串\出现的次数. 2.请描述冒泡排序算法的基本思想。

3.一个数组中只有0,1两种数字,进行排序,0全部在前,1全部在后

OOP部分

1.(单选)关于下列代码说法正确的是:

public class A { private int counter = 0; public static int getInstanceCount() { return counter; } public A() { counter++; } public static void main(String[] args) { A a1 = new A(); A a2 = new A(); A a3 = new A(); System.out.println(A.getInstanceCount()); } } A.该类编译失败 B.输出:1 C.输出:3

.

.

D.输出:0

2.试图编译和运行以下代码,将获得什么结果(JAVA)

class Base { int i = 99; public void amethod() { System.out.println(\ } Base() { amethod(); } } public class RType extends Base { int i = -1; public static void main(String argv[]){ Base b = new RType(); System.out.print(b.i+\ b.amethod(); RType r = (RType)b; System.out.print(r.i+\ } public void amethod(){ System.out.print(\ } } A RType.amethod -1 RType.amethod -1 B RType.amethod 99 RType.amethod -1 C 99 RType.amethod 99 D 编译时错误(Compile time error)

3、下边程序运行的结果是? ( )

class Base { Base() { System.out.print(\} public class Alpha extends Base { .

搜索更多关于: Java基础面试题及答案 的文档
Java基础面试题及答案.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c61jtc7edzl4ncj33s2bw8iiwn4795r018fl_1.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top