北航软件学院Java历届期末考题整理
文章目录
- abstract
- static
- Thread
- finally
- package
- Exception
- I/O
- 子类和父类
- 关键字
- 标识符
- 垃圾收集
- 数据类型
- 环境配置
- 网路编程
- initial
- 匿名类和内部类
- 语法
- 网页
abstract
what will be the result of attempting to compile and run the following code?
abstract class MineBase {
static int i;
abstract void amethod();
}
public class Mine extends MineBase {
public static void main(String arg[]){
int [] ar=new int[5];
for(i=0;i<ar.length;i++)
System.out.println(ar[i]);
}
}
A asequence of 5 0’s will be printed
B Error: ar is used before it is initialized
C Error Mine must be declared abstract
D IndexOutOfBoundes Error
C
A
B
D
static
写出编译运行后的结果
public class Student{
static int num;
int number;
public static int add1()
{
num=num+1;
return num;
}
public int add2()
{
number=number+1;
return number;
}
public static void main(String argv[])
{
Student zhang=new Student();
Student wang=new Student();
Student jiang=new Student();
System.out.println("zhang num="+add1());
System.out.println("zhang number="+zhang.add2());
System.out.println("wang num="+add1());
System.out.println("wang number="+wang.add2());
System.out.println("jiang num="+add1());
System.out.println("jiang number="+jiang.add2());
}
}
zhang num=1
zhang number=1
wang num=2
wang number=1
jiang num=3
jiang number=1
What will happen if you try to compile and run the following code
public class Test {
public static void main(String[] arguments) {
aMethod(arguments);
}
public void aMethod(String[] arguments) {
System.out.println(arguments[1]);
}
}
a)error Can’t make static reference to void amethod.
b)error method main not correct
c)error array must include parameter
d)aMethod must be declared with String
B
C
D
Thread
public class Test extends Thread {
static int aInt = 10;
public static void main(String[] argv) {
Test t = new Test();
t.start();
}
public void run() {
for (int i = 0 ; i < 4; i++) {
System.out.println(++aInt);
}
}
}
11
12
13
14
下列说法不正确的是:
a)Java中线程是抢占式的;
b)Java中线程可以是抢占式也可以是分时的;
c)Java中线程可以共享数器;
d)Java中线程可以共享代码。
Which method should you define as the starting point of a new thread in a class from which new threads of execution can be made?
a)public static void main(String[] args)
b)public void run()
c)public void start()
d)public void init()
e)public void runnable()
There are two ways to create a new thread of execution. One is to
declare a class to be a subclass of Thread. This subclass should
override the run method of class Thread.
The following code would then create a thread and start it running:
The other way to create a thread is to declare a class that implements
the Runnable interface. That class then implements the run method.
The following code would then create a thread and start it running:
下面哪个方法是启动新线程的方法:
a)只需创建
b)创建并调用start()
c)创建并调用begin()
d)创建并调用start Thread()
Java实现多线程的两种方法:
1.扩展java.lang.Tread类
2.实现java.lang.Runnable接口
public class Test extends Thread{
static String Sname="Hello";
public static void main(String argv[])
{
Test t=new Test();
t.start();
}
public void run()
{
for(int i=0;i<4;i++)
{
Sname=Sname+" "+i;
System.out.println(Sname);
}
}
}
Hello 0
Hello 0 1
Hello 0 1 2
Hello 0 1 2 3
finally
public class Test1 {
public static void main(String[] args) {
Test1 m = new Test1();
System.out.println(m.aMethod());
}
public int aMethod() {
try {
throw new Exception();
} catch (Exception ex) {
System.out.println("No such file found");
return -1;
} finally {
System.out.println("Doing finally");
}
}
}
No such file found
Doing finally
-1
别漏掉-1
public class Test1 {
public static void main(String[] args) {
print();
}
private static void print() {
try {
System.out.println("Thank your");
} finally {
System.out.println("I am sorry");
}
}
}
a)Thank you
b)I am sorry
c)Thank you
I am sorry
d)代码不能编译
public class Test1 {
public static void main(String argv[]) {
try {
System.out.println("Hello World!");
} catch (Exception e) {
System.out.println("Exception 1");
} finally {
System.out.println("Thank you!");
}
}
}
Hello World!
Thank you!
package
Package com.co.project;
Public class Test {
int i;
public int j;
protected int k;
private int l;
}
说法正确的是;
a)其它包中的所有类可以访问变量i;
b)其它包中的所有类可以访问变量j;
c)其它包中的所有类可以访问变量k;
d)其它包中的所有类可以访问变量l;
e)其它包中只有Test子类才能访问l。
Exception
所有异常的基础类是
a)String
b)error
c)Throwable
d)RuntimeException
下面代码的结果是
public class Test {
class B{}
public static void main(String[] args) {
new B();
}
}
a)compile time exception
b)runtime exception
c)compile with errors
d)一切正常
C
D
I/O
System是属于java中的哪一个包
a)lang
b)io
c)util
d)awt
关于System.out正确的是:
a)是一个OutputStream;
b)是一个PrintStream;
c)是一个FilterOutputStream;
d)异常时抛出IOException;
java API
try {
File f = new File("file.txt");
OutputStream out = new FileOutputStream("f.txt");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
a)不得编
b)可编,文件无改
c)可编,长度为0
d)抛出异常
这是个啥,反正我是没看懂
下面哪个语句能正确地创建一个InputStreamReader的实例:
a)new InputStreamReader(new FileInputStream(“data.txt”));
b) new InputStreamReader(new FileReader(“data.txt”));
c) new InputStreamReader(new BufferReader(“data.txt”));
d)new InputStreamReader( “data.txt”);
InputStreamReader参数必须是InputStream或其子类类型
.txt表示是一个文件(file)
FileReader();读入的是字符类型,不是字节(Stream)类型
DataInputStream只读入简单类型的变量
哪个语句可以建立”file.txt”的字节输入流:
a)FilelnputStream in =new FilelnputStream(”file.txt”);
b)InputStream in =new InputStream();
c)InputStream in =new FilefReaxder();
What will be printed out if this code is run with the following command line
public class MyProg {
public static void main(String argv[]) {
System.out.println(argv[2]);
}
}
a)MyProg
b)good
c)morning
d)Exception raised:”java.lang.ArrayIndexOutOfBoundsException:2”
A
这个实在是不知道该怎么弄出来
B、C
public class MyProg {
public static void main(String argv[]) {
System.out.println(MyProg.class);
System.out.println(argv);
System.out.println(argv[0]);
System.out.println(argv[1]);
}
}
javac MyProg.java
java MyProg good morning
class MyProg
[Ljava.lang.String;@15db9742
good
morning


也就是说java中main函数的命令行传参是不会把类名作为参数传递的,这点与C语言main函数传参不同
子类和父类
看程序输出
interface one {
}
class Two implements one {
}
class Three implements one {
}
public class Test {
public static void main(String[] argv) {
one test1 = new Two();
one test2 = new Three();
System.out.println(test1 instanceof one);
System.out.println(test2 instanceof one);
System.out.println(test1.getClass().equals(test2.getClass()));
}
}
true
true
false
What will happen if you attempt to compole and run the following code?
class Base{}
class Sub extends Base{}
class Sub2 extends Base{}
public class Test {
public static void main(String[] argv) {
Base b = new Base();
Sub s = (Sub) b;
System.out.println("everything is fine");
}
}
a)Compile and run without error
b)Compole time Exception
c)Runtime Exception
d)”everything is okay”
D
请问下面代码的结果
class base{}
class mine extends base{}
public class ss {
public static void main(String[] args) {
mine x = new mine();
base mm = (base)x;
System.out.println("sss");
}
}
a)compile time exception
b)runtime exception
c)sss
写输出
interface a{}
class AA implements a{}
class B implements a{}
public class Test{
public static void main(String[] args) {
a x = new AA();
a y = new B();
System.out.println(x instanceof a);
System.out.println(y instanceof a);
System.out.println(x.getClass().equals(y.getClass()));
}
}
true
true
false
关于接口的说法不正确的是:
a)接口所包含的方法既可以有时限,也可以没有实现;
(接口包含的方法不能有实现,抽象类才可以)
b) 接口没有构造函数;
c) 实现一个接口必须实现接口的所有方法;
d)接口间可以有继承关系。
下面关于方法覆盖不正确的是
a)在一个子类中一个方法不是public的就不能被重载;
b)子类重写父类的方法不能低于其在父类中的访问权限;
c)子类抛出的异常类型不能比父类抛出的异常类型更宽泛;
d)子类对父类方法重写时,要求重写方法参数列表和返回类型必须与被重写方法的相同。
Which of the following statements are true?
a)Methods cannot be overriden to be more private
b)static methods cannot be overloaded
c)private methods canot be overload
d)an overloaded method cannot throw exceptions not checked in the base class
overload(方法重载:方法名相同,参数不同) Static methods cannot be overriden but they
can be overloaded. There is no logic or reason why private methods
should not be overloaded. Option 4 is a jumbled up version of the
limitations of exceptions for overriden methods.
override(重写,覆盖)方法名,参数,返回值等都相同,是父类子类之间的关系
下列正确的是:
a)子类必须通过super关键字才能调用父类有参数构造的方法;
b)子类必须通过this关键字才能调用父类有参数构造的方法;
c)子类无条件继承父类不含参数的构造方法;
d)如果子类定义自己含参数的构造方法,就不能再调用父类的构造方法。
public class Fatherclass {
public Fatherclass() {
System.out.println("Father class create");
}
}
public class Childclass extends Fatherclass{
public Childclass() {
System.out.println("Child class create");
}
public static void main(String[] args) {
Fatherclass fc = new Fatherclass();
Childclass cc = new Childclass();
}
}
Father class create
Father class create
Child class create
实现继承的关键字是:
extends
Java中实现多继承的方法是:
a)继承多个类
b)继承多个抽象类
c)多个接口
d)不可以实现多继承
关键字
不能被继承的类是用___关键字修饰的:
a)static
b)print
c)final
d)protected
哪个关键字可抛出异常:
a)transient
b)finally
c)throw
d)static
Which modifier should be
applied to a method for the lock of the object(对象锁) this to be obtained
prior to excuting any of the method body?
a) abstract
b)final
c)protected
d)static
e)synchronized
标识符
类名和文件名的关系是:
Java保存的文件名必须与类名一致
如果文件中只有一个类,文件名必须与类名一致
一个Java文件中只能有一个public类
不止一个类,文件名必须与public类名一致
文件中不止一个类,且没有public类,那么文件名可与任一类名一致
垃圾收集
关于Java垃圾收集,下列哪个是正确的:
a)垃圾收集机制将检查并回收不再使用的内存;
b)垃圾收集机制允许开发者明确制定并释放该内存;
c)程序开发者必须自己创建一个线程运行内存释放工作;
d)垃圾收集机制能在期望时间内释放被Java对象使用的内存。
数据类型
下面哪个赋值语句是不正确的:
a)long a=6;
b)double-=99l;
c)float z=12.414f;
d)float z=12.414;
下面哪个不是Java的原始数据类型:
a)“abc”
b)’x’
c)100.09f
d)false
Which of the following lines will compile without warning or error.
a)float f = 1.3;(double)
b)char c = “a”;(java.lang.String)
c)byte b = 257;(int)
d)boolean b = null;(null)
e)int i = 10;
阅读以下程序,选择结果:
boolean a=false;
boolean b=true;
boolean c=(a&&b)&&!b;
int result = c == false?1:2;
a)c:false;result:1;
b)c:false;result:2;
b)c:true;result:1;
d)c:true;result:2;
下列对String类说法正确的是
a)是基本数据类型(不是基本数据类型)
b)可以继承(String类有final修饰符,不可以被继承)
c)length()是String的属性(length是数组的一个属性,而length()是字符串的一个方法)
d)不允许使用“==”判断相等
环境配置
系统环境变量配置中%JAVA_HOME%代表:
指向Java的JDK的安装目录的根目录
网路编程
下列写法正确的URL地址是
a)http:166.111.136.3:-10/index.html
b)ftp://166.11.136.3/incoming
c)ftp://166.111.136.3:-1/
d)http://166.111.136.3.3
URL结构
protocol(协议名):// host(主机名) [:port(端口号)] / path(文件目录或文件名) / [;parameters] [?query] #fragment
initial
public class StaticTest {
public static int printStr1() {
System.out.println("这是静态方法!");
return 0;
}
public int printStr2() {
System.out.println("这是普通方法!");
return 0;
}
public static void main(String[] args) {
StaticTest.printStr1();
StaticTest st = new StaticTest();
st.printStr2();
}
}
这是静态方法!
这是普通方法!
需要注意:
public class StaticTest {
public static int printStr1() {
System.out.println("这是静态方法!");
return 0;
}
public int printStr2() {
System.out.println("这是普通方法!");
return 0;
}
public static void main(String[] args) {
StaticTest st = new StaticTest();
st.printStr2();
StaticTest.printStr1();
}
}
这是普通方法!
这是静态方法!
What is the result with the following code?
class A {
public A() {
System.out.print("A");
}
}
class B extends A {
public B() {
System.out.print("B");
A a = new A();
}
}
public class Test {
public static void main(String[] argv) {
B b = new B();
}
}
a)ABA
b)BA
c)A
d)Compile with some errors
以下代码的输出是
public class Test {
public static int a;
public static void main(String[] args) {
System.out.println(a);
}
}
a)0
b)1
c)null
d)error
What will happen when you compile and run the following code?
public class MyClass {
static int i;
public static void main(String[] argv) {
System.out.println(i);
}
}
a)Error Variable i may not have been initialized
b)null
c)1
d)0
public class MyClass {
static int i;
static int j;
static String k;
//int l; //无法从静态上下文中引用非静态变量,无法通过编译
public static void main(String[] argv) {
int l;
System.out.println(i);//
System.out.println(++j);//
System.out.println(k);//null
//System.out.println(l);//可能尚未初始化,运行时错误
}
}
What will happen if you try to compile and run the following code?
public class Q {
public static void main(String[] args) {
int anArray[] = new int[5];
System.out.println(anArray[0]);
}
}
a)Error:anArray is referenced before it is initialized
b)null
c)0
d)5
别看他没在这初始化,而且是局部的,但是他不是个简单数据类型,它的那个new就初始化了,所以不能选A
A
B
匿名类和内部类
What will happen if you attempt to compile and run the following code?
public class Test {
public static void main(String[] argv) {
new B();
}
class B {
B() {
System.out.println();
}
}
}
a)Compile without error
b)Compile time Exception
c)Running time Exception
d)Compile with errors
语法
What will be the result of attempting to compile and run the following code?
public class Test {
public static void main(String[] args) {
int i = 1;
switch (i) {
case 0:
System.out.println("zero");
break;
case 1:
System.out.println("one");
case 2:
System.out.println("two");
default:
System.out.println("default");
}
}
}
a)one
b)one, default
c)one, two, default
d)default
不要忘记了default,因为2后面也没有break,就像一根一通到底的水管。
网页
What should you use to position
a Button within an application Frame so that the size of the Butten is
not affected by the Frame size?
a) a FlowLayout
b)a GridLayout
c)the center area of a BorderLayout
d)the East or West area of a BorderLayout
e)the North or South area of a Borderlayout
What should you use to position
a Button within an application frame so that the width of the Button is
affected by the Frame size but the height is not affected.
a)FlowLayout
b)GridLayout
c)Center area of a BorderLayout
d)North or South of a BorderLdyou
北航软件学院Java历届期末考题整理的更多相关文章
- Java 动态写轮眼 SharinganJPanel (整理)
/** * Java 动态写轮眼 SharingganJPanel (整理) * * 2016-1-2 深圳 南山平山村 曾剑锋 * 设计声明: * 1.虽然岸本是日本人,而我个人作为其模仿者,依 ...
- Java 动态眨眼 EyesJPanel (整理)
/** * Java 动态眨眼 EyesJPanel (整理) * * 2016-1-2 深圳 南山平山村 曾剑锋 * 注意事项: * 1.本程序为java程序,同时感谢您花费宝贵的时间来阅读本文档: ...
- Java 动态太极图 DynamicTaiChi (整理)
package demo; import java.awt.Color; import java.awt.Graphics; import javax.swing.JFrame; import jav ...
- Java Cardioid 心脏形曲线 (整理)
package demo; import java.awt.Color; import java.awt.Graphics; import javax.swing.JFrame; import jav ...
- Java笔试面试题整理第八波
转载至:http://blog.csdn.net/shakespeare001/article/details/51388516 作者:山代王(开心阳) 本系列整理Java相关的笔试面试知识点,其他几 ...
- Java笔试面试题整理第六波(修正版)
转载至:http://blog.csdn.net/shakespeare001/article/details/51330745 作者:山代王(开心阳) 本系列整理Java相关的笔试面试知识点,其他几 ...
- Java笔试面试题整理第五波
转载至:http://blog.csdn.net/shakespeare001/article/details/51321498 作者:山代王(开心阳) 本系列整理Java相关的笔试面试知识点,其他几 ...
- Java笔试面试题整理第四波
转载至:http://blog.csdn.net/shakespeare001/article/details/51274685 作者:山代王(开心阳) 本系列整理Java相关的笔试面试知识点,其他几 ...
- Java笔试面试题整理第三波
转载至:http://blog.csdn.net/shakespeare001/article/details/51247785 作者:山代王(开心阳) 本系列整理Java相关的笔试面试知识点,其他几 ...
随机推荐
- CentOS 7上的进程管理
一些杂乱的基础概念 程序是一种静态的文件,躺在磁盘上.而进程则是将程序运行起来放置于内存中.因此进程就是运行中的程序,是程序运行起来的一个实例.同一个程序可以运行为多个进程/实例. 进程之间有父子关系 ...
- Ansible-playbook之循环判断
1.循环 (loop) # 使用循环创建硬连接:x连接到y:z连接到k: - hosts: web - name: Create two hard links file: src: "{{ ...
- weui实现滚动加载的效果
weui是微信公司提供的一个UI框架,在H5开发中一些组件可以直接使用.weui文档地址:http://www.jqweui.cn/components 使用weui,需要引入weui.css和jqu ...
- 在Mac上安装JDK1.8及环境变量配置
今天我们来讲一讲,在Mac上的JDK安装. 第一步,打开终端输入 java -version 看看是否本地已经安装了JDK,如果未安装,OK,继续- 第二步,到官网下载JDK.勾选“Accept Li ...
- UWP 在ShellPage.xaml.cs 中导航至其他页面引发System.Exception
最近有一个需求,需要App监测网络变化,并在网络变化的同时用户,你切网啦,并且导航至一个切网的特定页面. 和Android.iOS的小伙伴后共同发现,人家有一个类似”拦截器“的框架,可以拦截App发出 ...
- Python - 文件分发小程序
一.概述 该小程序实现从源端到目标端的文件一键拷贝,源端和目标段都在一台电脑上面,只是目录不同而已 二.参数文件说明 1. settings.txt的说明 a. 通过配置settings.txt,填源 ...
- 简洁优雅的Python教你如何在工作中“偷懒”
前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者: A字头 PS:如有需要Python学习资料的小伙伴可以加点击下方链 ...
- CSS入门(css简介与样式汇总、CSS的使用方式和特征、CSS基础选择器和复杂选择器、边框阴影)
一.CSS的作用 1.以统一的方式实现样式的定义 2.提高页面样式的可重用性和可维护性 3.实现了内容(HTML)和表示(CSS)的分离 HTML和CSS之间有什么关系? HTML:构建网页的结构 C ...
- Android五大布局详解——FrameLayout(帧布局)
FrameLayout 这个布局相对前面两节介绍的布局就简单了很多,因此它的应用场景也就特别的少.这种布局没有方便的定位方式,所有的控件都会默认摆放在布局的左上角.新建UILayoutTestThre ...
- [MySQL] 使用force index强制使用索引
1.在测试一个按照时间的范围查询时,尽管增加了索引,发现使用不到索引,可以使用这个来强制使用索引 测试过程为,创建下面的表,以及创建了联合索引 create table delay_delete_us ...

















