📄 复赛.txt
字号:
1、使用以下哪个保留字可以使只有在定义该类的包中的其他类才能访问该类?
A)abstract B)private
C)protected D)不使用保留字
2、下列选项中哪一个是表达式1+2+"aa"+3的值()?
A)"12aa3"B) "3aa3"C) "12aa"D) "aa3"
3、考虑下面的类:
1. class Test {
2. void test(int i) {
3.System.out.println(“I am an int.”);
4. }
5. void test(String s) {
6.System.out.println(“I am a string.”);
7. }
8.
9. public static void main(String args[]) {
10. Test t=new Test();
11. char ch=“y”;
12. t.test(ch);
13. }
14. }
下列哪一个结论是正确的
A)第5行不能通过编译,因为void方法不能被重载。
B)第12行不能通过编译,因为没有将一个将char类型作为参数的test() 方法。
C)代码不能通过编译但是会在第12行抛出异常。
D)代码能通过编译并会产生如下输出:I am an int.
E)代码能通过编译并会产生如下输出:I am a String.
4、下列哪些代码编译时没有错误
A) int i=0;
if (i) {
System.out.println(“Hi”);
}
B) boolean b=true;
boolean b2=true;
if(b==b2) {
System.out.println(“So true”);
}
C) int i=1;
int j=2;
if(i==1|| j==2)
System.out.println(“OK”);
D) int i=1;
int j=2;
if (i==1 &| j==2)
System.out.println(“OK”);
5、如果float f=4.2F;
Float g=new Float(4.2F);
Double d=new Double(4.2);
则下列哪些表达式值为真?
A)f==g
B)g==g
C)d==f
D)d.equals(f)
E)d.equals(g)
F)g.equals(4.2)
6、public class Test{
public static void add3(Integer i){
int val=i.intValue();
val+=3;
i=new Integer(val);
}
public static void main(String args[]){
Integer i=new Integer(0);
add3(i);
System.out.println(i.intValue());
}
}
以上代码的结果会是以下哪个选项?
A) 编译出错。
B) 输出 "0"
C) 输出 "3"
D) 编译成功但运行时会在第3行出现异常
7、下面程序标记处应该插入哪个选项的代码?
class EnclosingOne{
public class InsideOne{}
}
public class InnerTest{
public static void main(String args[]){
EnclosingOne eo=new EnclosingOne();
//insert code here
}
}
A) InsideOne ei=eo.new InsideOne();
B) eo.InsideOne ei=eo.new InsideOne();
C) InsideOne ei=EnclosingOne.new InsideOne();
D) InsideOne ei=eo.new InsideOne();
E) EnclosingOne.InsideOne ei=eo.new InsideOne();
8、public class SychTest{
private int x;
private int y;
public void setX(int i){ x=i;}
public void setY(int i){ y=i;}
public Synchronized void setXY(int i){
setX(i);
setY(i);
}
public Synchronized boolean check(){
return x!=y;
}
}
在下列哪种情况下,check()方法在被另一个不同的类调用时会返回true?
A) check() 永远也不会返回true。
B) 当通过多线程调用setXY () 时check() 能够返回true。
C) 当通过多线程单独调用setX() 和setY()时check() 能够返回true。
D) 只有当SychTest 被改为允许x和y单独设值时check() 才能够返回true。
9、import java.awt.*;
public class X extends Frame{
public static void main(String[] args){
X x=new X();
x.pack();
x.setVisible(true);
}
public X(){
setLayout(new GridLayout(2,2));
Panel p1=new Panel();
add(p1);
Button b1=new Button("One");
p1.add(b1);
Panel p2=new Panel();
add(p2);
Button b2=new Button("Two");
p2.add(b2);
Button b3=new Button("Three");
p2.add(b3);
Button b4=new Button("Four");
add(b4);
}
}
当frame改变大小时,
A) 所有都会改变高度
B) 所有都会改变宽度
C) Button "One" 改变高度
D) Button "Two"改变高度
E) Button "Three" 改变宽度
F) Button "Four"改变高度和宽度
10、String或StringBuffer类的对象在调用以下哪个方法时其自身会发生更改?
A) String类的charAt()方法。
B) String类的toUpperCase()方法。
C) String类的replace()方法。
D) StringBuffer类的reverse ()方法。
E) StringBuffer类的length ()方法。
二. 简答题(每题5分,共10分)
1、说明final, finally, finalize的区别?
2、线程类的方法中sleep() 和 wait() 有什么区别?
三. 写出下列程序的输出结果(第1题5分,第2题10分,共15分)
1、以下程序段的输出结果为。
intj=2;
switch( j ) {
case2:
System.out.print(“Value is two.”);
case2+1 :
System.out.println(“Value is three.”);
break;
default:
System.out.println(“value is “+j);
break;
}
2、阅读以下程序段:
classParent
{
voidprintMe()
{
System.out.println(“parent”);
}
}
classChildextends Parent
{
voidprintMe()
{
System.out.println(“child”);
}
voidprintAll()
{
super.printMe();
this.printMe();
printMe();
}
}
public class Test_this
{
public static void main(Stringargs[ ])
{
ChildmyC=newChild();
myC.printAll();
}
}
输出结果为:
四. 编程题(共65分)
1、用LinkedList实现一个stack,实现其中的push(),top()和pop()方法;其中push()实现向栈中加入一个元素,top()实现得到栈的最顶元素,pop()实现删除最顶元素。(25分)
2、为Thread撰写两个子类,其中一个的run()在启动后取得第二个Thread object reference,然后调用wait()。另一个子类的run()在过了数秒之后调用notifyAll(),唤醒第一个线程,使第一个线程可以印出消息。(40分)
--------------------------------------------------------------------------------
附件:
复赛试题B卷
一.选择题(每道题3分,共30分)
1、异常包含下列哪些内容?
A)程序中的语法错误B)程序执行过程中遇到的事先没有预料到的情况
C)程序的编译错误D)程序事先定义好的可能出现的意外情况
2、编译下列源程序会得到哪些文件?
class A1{
}
class A2{
}
public class B{
public static void main(String args[]){
}
}
A) 只有B.class B)只有A1.class和 A2.class文件
C)有A1.class、A2.class和B.class文件D) 编译不成功
3、从下面中选择三个合法标识符。
A)IDoLikeTheLongNameClass
B)$byte
C)const
D)_ok
E)3_case
4、如何强制垃圾回收一个对象?
A)垃圾回收不能被强制执行。
B)调用System.gc()。
C)调用System.gc(), 将要回收对象的引用作为参数传入。
D)调用Runtime.gc()。
E)将所有指向该对象的引用赋成新值(比如null)。
5、给定以下类,哪个是hashCode()方法的正确实现?
class ValuePair {
public int a, b;
public boolean equals(Object other) {
try {
ValuePair o = (ValuePair) other;
return (a == o.a && b == o.b)
|| (a == o.b && b == o.a);
} catch (ClassCastException cce) {
return false;
}
}
public int hashCode() {
//Provide implementation here.
}
}
请选出3个正确答案。
A)return 0;
B)return a;
C)return a + b;
D)return a – b;
E)return a ^ b;
F)return (a << 16) | b;
6、哪个运算符会一直计算所有操作数?请选出两个正确答案。
A)||
B)+
C)&&
D)? :
E)%
7、如果str表示一个String对象“73”,那么以下哪些表达式将会把这个字符串转换为int值73?请选出两个正确答案。
A)Integer.intValue(str)
B)((int) str)
C)(new Integer(str)).intValue()
D)Integer.parseInt(str)
E)Integer.getInt(str)
8、关于switch结构的说法哪些是正确的?请选出1个正确答案。
A)所有switch说明都必须有一个默认标签。
B)在一个switch说明中,每个代码片断都必须正好有一个标签。
C)关键词continue永远不会在一个switch说明中出现。
D)在一个单一switch说明里,没有case标签可以跟随一个默认标签。
E)一个字符可以用做一个case标签的值。
9、 String a = “hello”;
String b = new String (a);
String c = a;
char[] d = {‘h’,‘e’,‘l’,‘l’,‘o’};
请从以下选项中选出两个值为真的表达式。
A)(a == “Hello”)
B)(a == b)
C)(a == c)
D)a.equals(b)
E)a.equals(d)
10、String或StringBuffer类的对象在调用以下哪个方法时其自身会发生更改?
A)String类的charAt()方法。
B)String类的toUpperCase()方法。
C)String类的replace()方法。
D)StringBuffer类的reverse ()方法。
E)StringBuffer类的length ()方法。
二、简答题(每题5分,共10分)
1、简述Overload和Override的区别。Overloaded的方法是否可以改变返回值的类型?
2、Abstract Class和Interface有什么区别?
三、写出下列程序的输出结果(第1题5分,第2题10分,共15分)
1、写出以下程序的运行结果。
class MyException extends Exception{
private int detail;
MyException( int a ){detail = a;}
public String toString( ){return "MyException "+detail; }
}
public class ExceptionDemo{
public static void compute(int a) throws MyException{
System.out.println("called compute("+a+")");
if( a>10 )throw new MyException(a);
System.out.println("normal exit");}
public static void main( String args[] ){
try{compute(6 );compute( 12 );}
catch( MyException e ){System.out.println("Caught "+e); }}
}
2、写出以下程序的运行结果。
classStaticTest {
staticintx=1;
int y;
StaticTest()
{y++;}
publicstaticvoidmain(Stringargs[ ]){
StaticTestst=new StaticTest();
System.out.println("x=" + x);
System.out.println("st.y=" + st.y);
st=new StaticTest();
System.out.println("st.y=" + st.y);}
static{ x++;}
}
四、编程题(共65分)
1、用Linklist实现一个队列quene;实现put()方法向队列中加入一个元素,get()方法得到第一个元素,isEmpty()判断是否为空。(25分)
2、撰写一个 myString class,其中包含一个String对象,可于构造函数中通过引数来设定初值。加入toString()和concatenate()。后者会将String对象附加于你的内部字符串尾端。请为myString()实现clone()。撰写两个static函数,令它们都接收myString referencex引数并调用x.concatenate(“test”)。但第二个函数会先调用clone()。请测试这两个函数并展示其不同结果。(40分)
--------------------------------------------------------------------------------
附件:
决赛试题 Java程序设计
编程题:(共1题,180分)
一.构建一个简单的在线购物系统,系统采用B/S结构,基本功能包括:商品的添加、删除和查询以及购物车功能.
开发环境:数据库使用ACCESS。
功能模块:
1、商品的添加(40分)
建立商品信息表,包含字段:商品名,商品价格,商品描述,商品种类等。该模块实现将商品信息添加到表中。
基本样式如图1所示。
图1 添加商品页面
2、商品的查询(40分)
允许组合多种查询条件查询系统商品,这些条件包括商品种类,商品名等。要求种类用下拉列表框表示,商品名使用文本框接收输入。查询采取模糊查询的方式。查询页面的基本样式如图2所示。
图2 商品查询页面效果图
在图2中输入查询条件,点击确认后,可查看到图3所示页面。
图3 查询结果
3、在该页面可以选择删除记录。(40分)
注:该系统中的商品类别静态指定,有日用品、文具、玩具、饰物四种。以上图片仅供参考,编程人员可以自行扩展设计商品信息表,但商品名,商品价格,商品描述,商品种类4项是必需的。查询条件也可添加,但不能减少。
4、购物车功能(60分)
1) 将商品添加到购物车
2) 从购物车中删除商品
用户可自行修改购买商品的数量,系统根据用户购买的商品及数量计算出每种商品的价格,同时计算出所有商品的消费价格。
--------------------------------------------------------------------------------
附件:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -