Java东华理工大学试卷A

更新时间:2023-09-03 23:49:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

大学2012 —2013 学年第 1 学期考试试卷

闭 课程类别:考查 A

b = false || true ;

System.out.println("b = "+b); } } What is the result?( )

A、b=false b=true B、b=true b= false C、b=true b= true D、b= false b= false 6. class example {

public static void main(String args[]) {

int i=1; a[i++]=a[i++]+2; System.out.println(a[i++]); }} What is the result?( )

A, 4 B, 5 C 3, D,6 7.public class Example{ String str=new String("good"); char[]ch={'a','b','c'};

public static void main(String args[]){ Example ex=new Example(); ex.change(ex.str,ex.ch); System.out.print(ex.str+" and ");

1 选择题(共35分)

1.What is suffix(后缀) of Java source code?( )? A、 .java B、.class C、.txt D、.ext 2. Which command can compile Java source code? ( )? A、 edit B、 dir C、 java D、javac 3. Which identifies is illegal ( )?

A、$_$123 B、_something C、some**name D、you_can_al 4. Which conversion (转换) is illegal ( )?

A、short x=1000; B、byte x=1000; C、byte x=100; D、float x=12L; 5.class example {

public static void main(String args[]) { boolean b;

b = (2 > 3) && (3 < 2); System.out.print("b = "+b);

专用考试纸 请勿浪费 卷 第1页 共9页

Sytem.out.print(ex.ch); }

public void change(String str,char ch[]){ str="test ok";

ch[0]='g'; } } What is the result?( )

A good and abc B good and gbc C test ok and abc D test ok and gbc

5. if(s1.equals(b1)){

6. System.out.println(“equal”);}}} A the program runs and prints nothing B the program runs and prints “equal” C An error at line 5 causes compilation to fail D The program runs but aborts with an exception

8. Set x=1,y=2,z=3, expression :y+=z--/++x what is result ( ) A 3 B 3.5 C 4 D 5

11.1.interface A{

9. what is result ( )?

2. int a=3;

class example{

3. void show();

static int a=3;

4.}

public static void main(String args[]){

5.class B implement A{

new example().a++;

6. void show(){}

new example().a+=2;

7.public static void main(String args[]){

System.out.println(example.a);}}

8. System.out.println(a++);}}

A 6 B 7 C 4 D 5

Which lines are incorrect when the code is compiled?( )

10. 1.class X{

A 5 7 B 6 8 C 5 6 8 D 5 6

2.public static void main(String args[]){

12 class A{

3. String s1=new String(“true”);

int a=2;}

4. Boolean b1=new Boolean(true);

class B extends A{

专用考试纸 请勿浪费 卷 第2页 共9页

int a=3;} class test{

public static void main(String args[]){ A g=new B();

System.out.println(g.a);}}What is result? ( ) A 2 B no result C 1 D 3 13 what is result ( ) class A{

public static void main(String args[]){ try{ int a=1/0; int []b={1,2}; b[4]=4; }

catch(ArrayIndexOutOfBoundsException e){ System.out.print("vvv"); }

catch(ArithmeticException e){ System.out.print("rrr"); }

finally{

System.out.println("sss"); } } }

A rrrvvv B rrrsss C vvvsss D sssrrr 14. class A{

final int i4=(int)(Math.random()*20); static final int i5=(int)(Math.random()*20); public void print(){

System.out.println("i4="+i4+"i5="+i5);} public static void main(String args[]){ A g1= new A(); g1.print(); A g2= new A(); g2.print(); }}

Assume i4=15 i5=16 when g1.print() method is executed . what result is displayed when g2.print() is executed( )

A 15 16 B 15 17 C 18 14 D 15 15 15.class A{

void f(int x){System.out.println(x);}

专用考试纸 请勿浪费 卷 第3页 共9页

void f(long x){System.out.println(x);} public static void main(String args[]) { A g1= new A(); g1.f(5.6); }} What is result( )

A 5.6 B 5 C 6 D error 二、翻译题20分,每小题5分

1)Encapsulation is the mechanism that binds together code and the data it manipulates, and keep both safe from outside interference and misuse.

2)Encapsulation allows an object to separate its interface from its implementation. The data and the implementation code for the object

are hidden behind its interface. So encapsulation hides internal implementation details from users. The power of encapsulated code is that everyone knows how to access it and thus can use it regardless of the implementation details and without fear of unexpected side effects.

3)In Java the basis of encapsulation is the class. A class defines the structure and behavior (data and code) that will be shared by a set of

专用考试纸 请勿浪费 卷 第4页 共9页

defined by the class, as if it were stamped out by a mold in the shape of the class. For this reason, objects are sometimes referred to as instance of class. Thus, a class is a logical construct; an object has physical reality.

4)When you create a class, you will specify the code and data that constitute that class. Collectively, these elements are called members of the class. Specifically the code that operates on that data is referred to as member variables or instance variables.

三 程序阅读题(每题4分,共计20分):

The result of following program is:_________________________ import java.io.*; public class UseLabel

{ public static void main(String[] args) {

Loop:

专用考试纸 请勿浪费 卷 第5页 共9页

} } }

The result of following program is: _________________________ import java.io.*; public class Class1 {

public static void main(String args[]){

int i,ax,in;

int a[] = {12,67,8,98,23,56,124,55,99,100); ax= in= a[0];

for(i=1; i<a.length; i++){ }

if( a[i]< in) in = a[i]; if( a[i]> ax) ax = a[i];

for(int i=2; i<10; i++) { for(int j=2;j<i;j++)

if( i%j == 0) continue Loop; System.out.print(i+" ");

System.out.println( ax + " " + in); System.out.println();

} }

The result of following program is: _________________________ class A { int a; A(){ a=1 ;} A(int b) {a=b;} void show() {

System.out.println(“a=”+a);} }

public class Class1 {

public static void main (String args[]) {

专用考试纸 请勿浪费 卷 第6页 共9页

A a1=new A(12); A a2=new A(); a1.show(); a2.show(); boolean b=false; char ch=65;

System.out.println(“b=”+b+”\tch=”+ch); } }

The result of following program is: _________________________ class A{ }

class B extends A{ int x; int x; void print(){ }

System.out.println("x in A:"+x);

}

public class HideFields {

public static void main(String[] args) { B b=new B(); void output(){ } x=32; super.x=54; print();

System.out.println("x is B:"+x);

b.output(); }

The result of following program is: _________________________

public class ArithmeticException {

public static void main(String args[]){

int a,b,c; }

专用考试纸 请勿浪费 卷 第7页 共9页

} }

System.out.println("java程序运行结束! "); try{ a=9; b=0; c=a/b;

System.out.println(a+"/"+b+"="+c);

四、编程题25分

1.Write a program which cast one integer to byte, one double to int and one double to byte..(10分)

专用考试纸 请勿浪费 卷 第8页 共9页

}catch(ArithmeticException e){

System.out.println("出现被0除的异常情况");

} finally{ }

System.out.println("除数="+a); System.out.println("被除数="+b);

、Write a program that print all strings which consists of 1 , 3 , 5 , 8 , 9 .(输出由字符1,3,5,8,9组成的所有可能字符串)(15分)

专用考试纸 请勿浪费 卷 第9页 共9页

本文来源:https://www.bwwdw.com/article/4upi.html

Top