牛客刷题总结8

1.Which method you define as the starting point of new thread in a class from which n thread can be execution?下列哪一个方法你认为是新线程开始执行的点,也就是从该点开始线程n被执行

        答:        public void run()

2.下列选项中不属于结构化查询语言的组成部分的是

        答:        数据字典

3.下面代码输出结果是

class C {
    C() {
        System.out.print("C");
    }
}
 
class A {
    C c = new C();
 
    A() {
        this("A");
        System.out.print("A");
    }
 
    A(String s) {
        System.out.print(s);
    }
}
 
class Test extends A {
    Test() {
        super("B");
        System.out.print("B");
    }
 
    public static void main(String[] args) {
        new Test();
    }
}

        答:        CBB

        拓展:        类的加载顺序  父类静态成员变量、静态块>子类静态成员变量、 静态块>父类普通成员变量、非静态块>父类构造函数>子类 普通成员变量、非静态块>子类构造函数

4.运行代码,输出的结果是

public class P {
    public static int abc = 123;
    static{
        System.out.println("P is init");
    }
}
public class S extends P {
    static{
        System.out.println("S is init");
    }
}
public class Test {
    public static void main(String[] args) {
        System.out.println(S.abc);
    }
}

        答:        P is init<br />123

        拓展:     不会初始化子类的几种情况             

                          调用的是父类的static方法或者字段

                          调用的是父类的final方法或者字段

                          通过数组来引用

5.存根(Stub)与以下哪种技术有关

        答:        动态链接

6.下列哪些字段适合建立索引

        答:        外键字段,主键字段,where条件中的字段

        拓展:      select语句中的字段不适合建索引,建立索引是为了提高查找数据速度,而select是为了展示数据,不需要提高查找数据速度

7.以下程序执行后,正确的结果是

public class Test {
    private String name = "abc";
    public static void main(String[] args) {
        Test test = new Test();
        Test testB = new Test();
        String result = test.equals(testB) + ",";
        result += test.name.equals(testB.name) + ",";
        result += test.name == testB.name;
        System.out.println(result);
    }
}

        答:        false,true,true

        拓展:        equals()方法未重写比较的是两者的地址,test和testB对象是两个不同的对象,因此他们的地址不同,故返回结果为false,abc是通过字面量的方式赋值,第一次在常量池中发现没有abc,第二次发现常量池里面有,故两次得到的abc是同一个对象,且该对象被同一个引用指向,故返回true,第三个true也是同样的道理

8.下面的switch语句中,x可以是哪些类型的数据

        答:        char,byte,String

        拓展:        switch语句中只可以是int类型,但又是如何支持10种类型的呢,因为这10种类型可以转化为int类型,这十种类型分为:byte,short,int,char,Byte,Short,Integer,Character,String,enum

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值