java基础10题

1.java中可以将布尔值与整数进行比较吗 ?
A.可以
B.不可以
2.观察下列代码,分析结果()

String s1 = "coder";     
String s2 = "coder";     
String s3 = "coder" + s2;     
String s4 = "coder" + "coder";     
String s5 = s1 + s2;            
System.out.println(s3 == s4); 
System.out.println(s3 == s5);    
System.out.println(s4 == "codercoder");

3.对于同一类中的两个方法 , 在判断它们是不是重载方法时 , 肯定不考虑( )
A.参数个数
B.参数类型
C.返回值类型
D.参数顺序
4.下面代码输出结果为

class A {
    public A() {
        System.out.println("class A");
    }
    { System.out.println("I'm A class"); } 
    static { System.out.println("class A static"); }
}
public class B extends A {
    public B() {
        System.out.println("class B");
    }
    { System.out.println("I'm B class"); }
    static { System.out.println("class B static"); }
    
    public static void main(String[] args) { 
 new B(); 

5.下面哪个不对?
A.RuntimeException is the superclass of those exceptions that can be thrown during the normal operation of the Java Virtual Machine.
B.A method is not required to declare in its throws clause any subclasses of RuntimeExeption that might be thrown during the execution of the method but not caught
C.An RuntimeException is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch.
D.NullPointerException is one kind of RuntimeException
6.下面代码循环次数为

public class Test {
    public static void main(String args[]) {
        int i = 7;
        do {
            System.out.println(--i);
            --i;
        } while (i != 0);
            System.out.println(i);
    }
}

7.Java数据库连接库JDBC用到哪种设计模式?
A.生成器
B.桥接模式
C.抽象工厂
D,单例模式
8.下面代码输出结果为

class Animal{
    public void move(){
        System.out.println("动物可以移动");
    }
}
class Dog extends Animal{
    public void move(){
        System.out.println("狗可以跑和走");
    }
    public void bark(){
        System.out.println("狗可以吠叫");
    }
}
public class TestDog{
    public static void main(String args[]){
        Animal a = new Animal();
        Animal b = new Dog(); 
        a.move();
        b.move();
        b.bark();
    }
}

9.Java的体系结构包含( )。
A.Java编程语言
B.Java类文件格式
C.Java API
D.JVM
10.有关线程的哪些叙述是对的()
A.一旦一个线程被创建,它就立即开始运行。
B.使用start()方法可以使一个线程成为可运行的,但是它不一定立即开始运行。
C.当一个线程因为抢先机制而停止运行,它可能被放在可运行队列的前面。
D.一个线程可能因为不同的原因停止并进入就绪状态。

(1)B
boolean 类型不能转换成任何其它数据类型。
(2)false;false; true;
引用类型判断时,判断的是地址是否相等。如果用常量字符串来定义的(如s1,s2,s4)会存在常量池里面;用变量定义的就不会(如s3,s5)。所以上面的状态就是s1s2;s4==“codercoder”;s3!=s4;s3!=s5。
(3)C
关于D的疑问:
1.参数类型不同时,顺序不同也是重载,例如:
public void first(int a,double b ){}
public void first(double b2,int a2){}

2.参数类型相同时,没有顺序之分,例如:
public void first(int a,int b ){}
public void first(int b2,int a2){}
因为数据类型相同,不能说明谁前谁后,这里a,b,a2,b2,仅仅是变量名称而已。
(4)class A static
class B static
I’m A class
class A
I’m B class
class B
Java程序初始化顺序:
父类的静态代码块
子类的静态代码块
父类的普通代码块
父类的构造方法
子类的普通代码块
子类的构造方法
(5)C
a.虚拟机会自己抛出RuntimeException异常
b.RuntimeException异常不需要声明抛出或者被捕获
c.subclass:子类, RuntimeException不是Throable子类,是Exception的子类
意思:RuntimeException 是Throable并表明他是一个严重的问题,应该合理的被tracatch捕获
d:空指针异常(NullPointException)是 RuntimeException
(6)无限次
请认真看题目,–i 出现了两次,所以每次-2 ,永远不为0,会一直循环下去
(7)B
JDBC使用的是桥接模式
定义:将抽象部分与它的实现部分分离,使它们都可以独立的变化
意图:将抽象与实现解耦
(8)编译错误
编译看左边,运行看右边。也就是是编译的时候会把它当成左边的类型,运行的时候看右边类型的方法体。这个题动物类没有另一个方法,而b调用了,所以编译器会认为b是一个动物类,所以报错。这就是多态的特性吧
(9)正确答案: A B C D
(10)正确答案: B C D

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Nicholas_giao

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值