牛客网试题

1、输出结果是: BaseBase

class Base {
Base() {
System.out.print(“Base”);
}
}
public class Alpha extends Base {
public static void main( String[] args ) {
new Alpha();
//调用父类无参的构造方法
new Base();
}
}
Alpha继承父类Base ,new Alpha,会先执行一次Base里的代码块,new Base()会再次执行一次输出。

2、输出10

下面的方法,当输入为2的时候返回值是多少?
public static int getValue(int i) {
int result = 0;
switch (i) {
case 1:
result = result + i;
case 2:
result = result + i * 2;
case 3:
result = result + i * 3;
}
return result;
输入2的时候,进入case 2 result为4,但是没有break,会继续执行下去,case :3 ,result 为4+6=10、

3、constructor在一个对象被new时执行 (构造方法为 Scanner sc =new Scanner() )

(5分/5分)下列说法正确的有
1.
class中的constructor不可省略
2.
constructor必须与class同名,但方法不能与class同名
3.
constructor在一个对象被new时执行
4.
一个class只能定义一个constructor

4 执行结果 12

下面的程序执行结果是:
public static void main(String[] args) {
int i = 0;
for (i++; i++ < 10; i++);
System.out.println(++i);
}
for循环中i++执行一次,后面的i++执行一次, i++<10只做比较不执行,++i输出前执行。

5、 1中main(String[] args) 可以缩写 2中method没定义是返回值还是返回空 ,私有private也报错 3同 4定义的变量不对

下列哪些代码符合java规范:
1.
public static void main(){}
2.
public method(){ private Integer num; }
3.
public method(){ int num; System.out.println(num); }
4.
private $5person=5;

6、数组a不是静态数组无法放在静态方法中,需new对象,用对象调用。所以编译有错误。

public class Test{
long a[]=new long[10];
pubic static void main(String args[]){
System.out.println(a[6]);
}
}
哪一个选项是正确的( )。

7、 因为c没有返回值也没用void所以不对

(5分/5分)下列方法的声明中不合法的是
1.
float area( ){…}
2.
void area( ){…}
3.
area{…}
4.
int area(int r){…}

8、在子类构造方法的哪个地方可以调用其父类

1
任何地方
2.
构造方法的第一条语句
3.
构造方法的最后一条语句
4.
无法在子类构造方法中调用父类的构造方法

9、一直拆分即可 1+0+1+0+1+0+1+0+1+0

当n=5时,下列函数的返回值是:
int foo(int n)
{
if(n<2) return n;
return foo(n-1)+foo(n-2);

10、以下类型为Final类型的为

2.StringBuffer 3.String
1.
HashMap
2.
StringBuffer
3.
String
4.
Hashtable

11、不会

public static void main(String[] args) {
String a = new String(“myString”);
String b = “myString”;
String c = “my” + “String”;
String d = c;
System.out.print(a == b);
System.out.print(a == c);
System.out.print(b == c);
System.out.print(b == d);
}
1.
System.out.print(a == b)打印出来的是false
2.
System.out.print(a == c)打印出来的是true
3.
System.out.print(b == c)打印出来的是false
4.
System.out.print(b == d)打印出来的是true

12 1.3.5.6

关于Java中的数组,下面的一些描述,哪些描述是准确的:( )
1.
数组是一个对象,不同类型的数组具有不同的类
2.
数组长度是可以动态调整的
3.
数组是一个连续的存储结构
4.
一个固定长度的数组可类似这样定义: int array[100]
5.
两个数组用equals方法比较时,会逐个便利其中的元素,对每个元素进行比较
6.
可以二维数组,且可以有多维数组,都是在Java中合法的

13、 1 2 3

What is Static Method in Java()
1.
It is a method which belongs to the class and not to the object(instance)
2.
A static method can access only static data. It can not access non-static data (instance variables)
3.
A static method can call only other static methods and can not call a non-static method from it.
4.
A static method can not be accessed directly by the class name and doesn’t need any object

14、下列属于关系型数据库的是 1 2

1
Oracle
2.
MySql
3.
IMS
4.
MongoDB

15、下列哪些是java的关键字(多选) 1.3.5

1
default
2.
loop
3.
do
4.
Class
5.
null
6.
java

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值