Java基础整理-Java试题(一)

来源:互联网 发布:石油来源 知乎 编辑:程序博客网 时间:2024/06/05 11:33

学生时代挺鄙夷应试的,现在大四了, 学生时代马上就结束了,回顾整个Java语言基础,发现当初老师出的这套试题其实还是很全面的,至少还是很有针对性,现在找到工作了,甚至觉得很有纪念意义。
一、选择题(共20小题,每题1分,共计20分)
1.下面选项中属于Java关键字的是(B)
A、java B、int C、hello D、String

2.Java类的构成包括(D)
A、属性 B、方法 C、构造方法 D、以上都是

3.Scanner是(B)包中的一个类
A、java.lang B、java.util C、java.io D、java.awt

4.下面哪个关键字与访问权限无关(A)
A、class B、private C、public D、protected

5.按照约定俗成,下面选项中适合用做方法名称的是(C)
A、Hello B、Hello World C、printHello D、Student

6.下面哪个关键字可以用来判断对象的类型(C)
A、throw B、this C、instanceof D、try

7.若需要定义一个类变量或类方法,应使用修饰符(A)
A、static B、package C、private D、public

8.下面哪种异常属于运行时异常(A)
A、NullPointerException B、ClassNotFoundException
C、IOException D、FileNotFoundException

9.已知a是Book类中申明的成员变量,那么a可能的数据类型是(D)
A、String B、int C、Book D、都可能

10.下面程序语句错误的是(B)
A、int a=0; B、void b=null; C、Object o=null; D、int[] a=new int[5];

11.为Student类选择一个正确的构造函数形式(B)
A、public void Student(String name) B、public Student(String name)
C、public void student(String name) D、public student(String name)

12.已知变量a的值为null,请为a选择一个合适的数据类型(C)
A、int a; B、boolean a; C、char[] a; D、char a;

13.假设Person是一个Java类,并有一个默认的构造函数,下面哪个语句是正确的(A)
A、Person p=new String(“John”); B、Person p=”John”
C、String p=new Person().toString(); D、String p=new Person();

14.下面关于Java程序叙述错误的是(D)
A、main方法是程序运行的入口
B、一个Java程序由多个Java类构成
C、程序在运行前首先要将Java类编译成字节码文件
D、语法正确的程序总能正确的运行完毕

15.下面关于this关键字的使用一定错误的是(B)
A、return this; B、return new this(); C、return this.getInfo(); D、return this.age;

16.关于getInfo方法的申明,下面哪个选项是正确的(D)
A、public String getInfo(){return;}
B、public String getInfo(){return “”;}
C、public String getInfo(){return Unknown;}
D、public String getInfo(){String info; return info;}

17.下面关于抽象类的说法正确的是(C)
A、在抽象类中不能声明构造方法
B、在抽象类中不能声明属性变量
C、在抽象类中可以不声明抽象方法
D、在抽象类中不能申明具体的方法

18.下面关于Java类叙述错误的是(C)
A、任何一个Java类都有toString()方法
B、任何一个Java类都是Object的直接子类或者间接子类
C、任何一个Java类都可以作为父类派生出子类
D、任何一个Java类都是一个数据类型

19.假设Person是一个Java类,并且Student是Person的一个子类,那么下面的语句中一定错误的是(D)
A、Person p=new Person();
B、Student s=new Student();
C、Person p=new Student();
D、Student s=new Person();

20.已知Person类声明了一个形式为public void addFridend(String name)的方法,下面哪个选项不符合方法重载的规定(B)
A、public void addFriend()
B、public void addFriend(String friend)
C、public void addFriend(String[] friends)
D、public void addFriedn(Person[] friends)

二、辨析题,正确的画“√”,错误的画“×”并改正。(共5小题,每题2分,共计10分)
1.A general Java program may consist of multiple classes. Usually, in terms of their functionality, the program groups them into different user-defined packages.(√)
2.You can use a class name directly to access its static members.(√)
3.You can extend a new class from the predefined Java classes such as Object,Button,and String,etc.(√)
4.Given a java class Person and the statements a = new Person(“John”) and b = new Person(“John”), then the statement a==b will return true.(×)
5.You are permitted to use an interface as a data type to declare a variable.(√)

三、请改正下面程序中的语法错误。(共2小题,每题5分,共计10分)
1、

class MyException extends Exception{}public class Test{    private static void sayHello(String person)throws MyException{        if(person==null)throw new MyException();        System.out.println("Hello," + person);    }    public static void main(String[] args){        sayHello("John");        System.out.println("OK");    }}

改正后:
语法改错一
2、

class User{    private String name;    public User(String name){this.name=name;}}public class Employee extends User{}

改正后:
语法改错二

四、程序分析题(8小题,每题5分,共40分)

Program One
program1

Program Two
program2

Program Three
program3
Reading Program One and then answer questions 1-3
1.What is the output when running the program?
Person:John Age:18
2.Please present the members declared in class Person,including constructors.
3.Please give the detailed steps of constructing the Person object.

Reading Program One and then answer questions 4-6
4.What is the output when running the program?
2012-4-22
2012-4-10
2012-4-10
5.Please in terms of the program explain the main usage of the keyword this.
6.Please present the detailed running process of the program by using method invocation stack.

Reading Program One and then answer questions 7-8
7.What is the output when running the program?
Name:Mary Age:23
Name:John Age:18 School:NJUE
8.Virtual method invocation is one of the important characters of object-oriented programming. Please point out how the program applies the character.

五、程序设计题(共2小题,每题10分,共计20分)
1.Given the following class. Please complete the program such that it can run correctly and output the result as follows:
John’s friend:Alice
Alice’s friend:John
Given:
程序设计1-1
Complete:
程序设计1-2
2.Given the following class. Please complete the program such that it can run correctly and output a line of**********.
Given:
程序设计2-1
Complete:
这里写图片描述

0 0
原创粉丝点击