一、选择题(每题 3 分,共 30 分)
1、下列作为 java 中变量名在编译期间会报错的是( )
A、HelloWorld B、$HelloWorld
C、_HelloWolrd3 D、Hello-Wolrd
2、下面表达式正确的是?( )
A、byte b = 128; B、boolean b = 1;
C、long a = 100L; D、float f = 0.9239;
3. 下面关于数组的声明语句中,有语法编译错误的是:( )
A. int[] arr = new int[]{1,’A’,3};
B. int[] arr = null;
arr = {1,2,3,4,5};
C. int[][] arr = {{1,2,3}};
D. int[][] arr = new int[3][];
4、下列说法正确的是( )
A、java 的数组可以随时改变大小
B、String 字符串的长度和大小都是不可变的
C、局部变量和成员变量重名时以成员变量优先
D、使用 final 修饰的方法不能被继承
5、下面代码运行结果为:( )
public static void main(String[] args){
int x = 1, y = 1, z = 1;
if(x--==1&&y++==1||z++= =1) {
System.out.println(“x=”+x+”,y=”+y+”,z=”+z;);
}
}
A: x=0,y=2,z=1 B: x=1,y=2,z=1
C: 没有输出 D:x=0,y=2,z=2
6、下列没有语法编译错误的是:( )
A、public static void main(String[] args){
byte b1 = 1;
byte b2 = 2;
byte b = b1+b2;
}
B、public static void main(String[] args){
int n = 100;
while(n>0){System.out.println(n);
}
}
C、public static void main(String[] args){
int n;
for(int i = 0;i<10;i++){
n += i ;
}
}
D、public static void main(String[] args){
int n = 100;
for(;;){
}
System.out.println(n);
}
7、类 Test1 定义如下:
1.public class Test1{
2. public float aMethod(float a,float b){ }
3. ...
}
将以下哪种方法插入行 3 是不正确的。( )
A、public float aMethod(float a, float b,float c){ }
B、public float aMethod(float c,float d){ }
C、public int aMethod(int a, int b){ }
D、private float aMethod(int a,int b,int c){ }
8、以下程序的输出结果为
public class Test{
public static void main (String[] args){
String s = “abc”;
s = change(s);
s.toUpperCase();
System.out.println(s);
}
public static String change(String s){
s = “def”;
return s;
}
}
A、abc B、ABC C、def D、DEF
9、下列程序运行结果为:( )
public class Test2 {public static void main(String[] args) {
Integer t1 = 127;
Integer t2 = 127;
Integer t3 = 128;
Integer t4 = 128;
System.out.println(t1==t2);
System.out.println(t1.equals(t2));
System.out.println(t3==t4);
System.out.println(t3.equals(t4));
}
}
A、true,true,true,true B、false,true,false,true
C、true,true,false,true D、编译失败
10、给定 java 代码如下:
class Father{
public Father() {
System.out.println("Father");
}
}
class Child extends Father{
public Child() {
System.out.println("Child");
new Father();
}
}
public class Test {
public static void main(String[] args) {
Child c = new Child();
}
}
编译运行后,输出结果为( )
A、Child Father
B、Father Child
C、Father Father Child
D、Child Child Father
二、问答题(每题 5 分,共 30 分)
1、重载和重写的区别是什么
2、简述你所理解的面向对象是什么以及三大特性好处
3、抽象类和接口的区别是什么
4、this 和 super 有什么区别5、基本类型和引用类型在有什么区别
6、equals 和==的区别是什么,各自在什么情况下使用
三、编程题(每题 10 分,共 40 分)
1、手写冒泡排序
2、定义整数 n,计算 1+1/2+1/3+1/4+1/5+......1/n 的和
3、猴子吃桃子问题:猴子第一天摘下 N 个桃子,当时就吃了一半,还不过瘾, 就又吃了一
个。第二天又将剩下的桃子吃掉一半,又多吃了一个。以后每天都吃前一天剩下的一半
零一个。到第 10 天在想吃的时候就剩一个桃子了,求第一天共 摘下来多少个桃子?
4、分析如下程序的输出结果,并画出内存分析图
class ClassA{
int value;
}
public class TestClassA{
public static void main(String[] args){
int value = 10;
changeInt(value);
System.out.println(value);
ClassA ca = new ClassA();
ca.value = 10;
changeObject(ca);
System.out.println(ca.value);
}
public static void changeInt(int value){
++value;
}
public static void changeObject(ClassA ca){
ca.value++;
}
}
JAVA基础面试题
最新推荐文章于 2024-06-13 17:40:21 发布