Java 基础

 

 

1.     以下代码行的输出是(    C    )

public class Person {
    private String name="Person";
    int age=0;
}

public class Child extends Person {
        public String grade;
        public static void main(String[] args) {
   Person p=new Child();
   System.out.println(p.name);
  }
}


A   输出Person
B   没有输出
C   编译错误
D   运行错误

 

2.    以下程序运行的结果是   (D)

 

class Person{
 public Person(){
  System.out.println("this is a person");
 }
}

public class Teacher extends Person {
       private String name="Tom";
       public Teacher(){
        System.out.println("this is a teacher");
        super();
       }
       public static void main(String[] args) {
  Teacher teacher=new Teacher();
  System.out.println(this.name);
 }
}

 

A    this is a person

      this is  a teacher

     tom

B      this is  a teacher

        this is  a  person

       tom

 

C   运行出错

D   编译有2 行错误

 

 

3.以下代码描述正确的是(A)
public interface IDemo {
          public static final String name;1
          void print();  2
          public void getInfo();  3
         
}
abstract class Person implements IDemo{  4
 public void print(){
  
 }
}
A 第一行错误,没有给变量赋值
B 第二行错误,方法没有修饰符
C 第四行错误,没有实现接口的全部方法
D 第三行错误,没有方法的实现

 

4. 以下程序运行的结果是  (A)
public class Test extends father {
  private String name="test";
  public static void main(String[] args) {
  Test test=new Test();
  System.out.println(test.getName());
 }
}

class father{
  private String name="father";
  public String getName(){
   return name;
  }
}

 

 


A father
B test
C 编译出错
D 运行出错,无输出

5.  下面代码运行的结果是  (  B)

public class Demo {
        public int add(int a,int b){
         try {
    return a+b;
   } catch (Exception e) {
    System.out.print("catch语句块");
   }finally{
    System.out.print("finally语句块");
   }
         return 0;
        }
        public static void main(String[] args) {
   Demo demo=new Demo();
   System.out.println("和是:"+demo.add(9, 34));
  }
}

 

A  编译异常

B  finally语句块和是:43

C 和是:43 finally语句块

D catch 语句块 和是: 43

 

 

6. 以下程序运行的结果是 (D)
public class Test {
  public int div(int a,int b){
   try {
   return a/b;
  } catch (Exception e) {
   System.out.println("Exception");
  }catch (ArithmeticException e) {
   System.out.println("ArithmeticException");
  }finally{
   System.out.println("finally");
  }
  
   return 0;
  
  }
  public static void main(String[] args) {
  Test test=new Test();
  System.out.println("商是:"+test.div(9,0));
 }
}


A  Exception finally 商是:0
B  ArithmeticException finally 商是:0
C  finally 商是:0
D  编译报错

 

7. 在Java中,以下代码( A )正确地创建了一个InputStreamReader对象。
A) InuptStreamReader(new FileInputStream(“1.dat”));
B) InuptStreamReader(new FileReader(“1.dat”));
C) InuptStreamReader(new BufferReader(“1.dat”));
D) InuptStreamReader (“1.dat”);

 

 

8. 在Java中,( D )类提供定位本地文件系统,对文件或目录及其属性进行基本操作。
A) FileInputStream
B) FileReader
C) FileWriter
D) File

 

9. Java中的集合类包括ArrayList、LinkedList、HashMap等类,下列关于集合类描述错误的是(C)(选择一项)
A) ArrayList和LinkedList均实现了List接口
B) ArrayList的访问速度比LinkedList快
C) 添加和删除元素时,ArrayList的表现更佳
D) HashMap实现Map接口,它允许任何类型的键和值对象,并允许将null用作键或值

10. 分析下面这段Java代码,它的运行结果是( C )。
Import java.io.*;
Public class B{
Public static void main(string [] args){
int i=12;
System.out.println(i+=i-=i*=i);}}

A) 100
B) 0
C) -120
D) 程序无法编译

 

 

11.. 存储过程pro有两个参数,第一个为输入参数,第二个为输出参数,以下代码正确的是(C)
A) CallableStatement cst=con.prepareCall(“(call pro(?,?))”);
B) CallableStatement cst=con.prepareCall(“(call pro(?))”);
C) CallableStatement cst=con.prepareCall(“{call pro(?,?)}”);
D) CallableStatement cst=con.prepareCall(“{call pro(?,?,?)}”);

 

 

12. 以下描述不正确的有(D)
A) try块不可以省略
B) 可以使用多重catch块
C) finally块可以省略
D) catch块和finally块可以同时省略

 

13. 根据下面的代码,
String s = null;
会抛出NullPointerException异常的有(A,C)。[两项]
A) if( (s!=null) & (s.length()>0) )
B) if( (s!=null) & & (s.length()>0) )
C) if( (s==null) | (s.length()==0) )
D) if( (s==null) || (s.length()==0) )

14. 访问修饰符作用范围由大到小是(D)
A) private-default-protected-public
B) public-default-protected-private
C) private-protected-default-public
D) public-protected-default-private

 要删除book表中书籍(bookName)是”java”的记录,以下代码正确的是(A
String sql=”delete from book where bookName=?”;
PreparedStatement pst=con.preparedStatement(sql);
pst.execute();
A) pst.setString(1,”java”);
B) pst.setString(0,”java”);
C) pst.setInt(0,”java”);
D) 以上选项都不正确

 

转载于:https://www.cnblogs.com/satisfysmy/p/9080189.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值