`
ss1
  • 浏览: 77784 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

java基础题

阅读更多

一、判断题(30分)
1
Java程序里,创建新的类对象用关键字new,回收无用的类对象使用关键字free N

2
.对象可以赋值,只要使用赋值号(等号)即可,相当于生成了一个各属性与赋值对象相同的新对象。N

3
.有的类定义时可以不定义构造函数,所以构造函数不是必需的。N

4
.类及其属性、方法可以同时有一个以上的修饰符来修饰。Y

5
Java的屏幕坐标是以像素为单位,容器的左下角被确定为坐标的起点。Y

6
.抽象方法必须在抽象类中,所以抽象类中的方法都必须是抽象方法。。N

7
Final类中的属性和方法都必须被final修饰符修饰。N

8
.最终类不能派生子类,最终方法不能被覆盖。Y

9
.子类要调用父类的方法,必须使用super关键字。N

10
.一个Java类可以有多个父类。不知道接口算不算父类

11
.如果p是父类Parent的对象,而c是子类Child的对象,则语句c = p是正确的。。N

12
.在java集合中,VectorHashMap是线程安全的。。N

13
.当一个方法在运行过程中产生一个异常,则这个方法会终止,但是整个程序不一定终止运行。。Y

14
.接口是特殊的类,所以接口也可以继承,子接口将继承父接口的所有常量和抽象方法。。Y

15
.用“+”可以实现字符串的拼接,用- 可以从一个字符串中去除一个字符子串。。N


二、选择题(30分)

1
、关于垃圾收集的哪些叙述是正确的(  C ):

A
.程序开发者必须自己创建一个线程进行内存释放的工作

B
.垃圾收集允许程序开发者明确指定并立即释放该内存

C
.垃圾收集将检查并释放不再使用的内存

D
.垃圾收集能够在期望的时间释放被java对象使用的内存

2
、下面的哪些赋值语句是不正确的(A   ):

A
float 
f=11.1;
B
double 
d=5.3E12;
C
double 
d=3.14159;
D
double d=3.14D

3
、下面关于变量及其范围的陈述哪些是不正确的(B   ):

A
.实例变量是类的成员变量

B
.实例变量用关键字static声明

C
.在方法中定义的局部变量在该方法被执行时创建

D
.局部变量在使用前必须被初始化

4
、下列关于修饰符混用的说法,错误的是( BCD ):

A
abstract不能与final并列修饰同一个类

B
abstract类中不可以有private的成员

C
abstract方法必须在abstract类中

D
static方法中能处理非static的属性

5
、容器PanelApplet缺省使用的布局编辑策略是( B   ):

A
BorderLayout  BFlowLayout      CGridLayout      D
CardLayout
6
、以下标识符中哪项是不合法的C  )

A
BigMeaninglessName                     B
$int
C
1 st                                    D
$1
7
main方法是Java  Application程序执行的入口点,关于main方法的方法头以下哪项是合法的(  B  ):

A
    public  static  void  main()
   
B
    public  static  void   mainString[ ]  args

C
    public  static int  mainString[ ]  arg

D
    public  void  mainString  arg[ ]

8
、执行完以下代码int [ ]  x = new  int[25];后,以下哪项说明是正确的(A    ):

A
    x[24]
0
B
    x[24]未定义

C
    x[25]
0
D
    x[0]为空

9
、以下代码段执行后的输出结果为(   B  ):

       int  x=3
int  y=10

       System.out.println(y%x);
A
0
B
1
C
2
D
3
10
、以下哪个表达式是不合法的(  B  ):

A
String  x=”Hello”;   int  y=9;   x+=y;
B
String  x=”Hello”;   int  y=9;  if(x= =y)  { }
C
String  x=”Hello”;  int  y=9;  x=x+y;
D
String  x=null;  int  y=(x!=null)&&(x.length()>0) ? x.length : 0
11
、编译运行以下程序后,关于输出结果的说明正确的是 C    ):

       public  class   Conditional{
              public  static  void  main(String  args[  ]){
                     int  x=4;
                     System.out.println(“value  is  “+ ((x>4) ? 99.9 :9));
}
}
A
    输出结果为:
value  is  99.99
B
    输出结果为:
value  is  9
C
    输出结果为:value  is  9.0
D
    编译错误

12
、以下声明合法的是( B    ):

A
    default  String  s

B
    public  final  static  native  int  w( )
C
    abstract  double  d

D
    abstract  final  double  hyperbolicCosine( )
13
、关于以下application的说明,正确的是(  C  ):

1
  class   StaticStuff
2
{
3
                  static  int  x=10

4
                  static  { x+=5
}
5
                  public  static  void  mainString  args[ ]

6
                  {
7
                       System.out.println(“x=” + x);
8
                  }
9
                  static  { x/=3;}
10.   }
A
4行与9行不能通过编译,因为缺少方法名和返回类型
 
B
9行不能通过编译,因为只能有一个静态初始化器

C
编译通过,执行结果为:
x=5
D
、编译通过,执行结果为:
x=3
14
、关于以下程序代码的说明正确的是( D  ):

1
class  HasStatic{
2
    private  static  int  x=100

3
    public  static  void  main(String  args[  ]){
4
        HasStatic  hs1=new  HasStatic(  );
5
        hs1.x++;
6
        HasStatic  hs2=new  HasStatic(  );
7
        hs2.x++;
8
        hs1=new  HasStatic( );
9
        hs1.x++;
10
       HasStatic.x- -;
11
       System.out.println(“x=”+x);
12
   }
13
}
A
5行不能通过编译,因为引用了私有静态变量

B
10行不能通过编译,因为x是私有静态变量

C
、程序通过编译,输出结果为:
x=103
D
、程序通过编译,输出结果为:
x=102
15
、以下选项中循环结构合法的是( C   ):

A
while (int  i<7){
     i++;
     System.out.println(“i is “+i);
}
B
int  j=3;
while(j){
   System.out.println(“ j  is “+j);
}
C
int  j=0;
for(int  k=0; j + k !=10; j++,k++){
    System.out.println(“ j  is “+ j + “k  is”+ k);
}
D
int  j=0;
do{
        System.out.println( “j  is “+j++);
        if (j = = 3) {continue  loop;}
}while  (j<10);

三、简答题(40分)

1.   
写出下列程序的运行结果

public class Cat
{
  

  void mi( ) throws NullPointerException  {
    System.out.println( “Cat mi mi .. “ );
  }
}
public class SmallCat extends Cat
{int i=8;
  void mi( ) throws Exception
  {
    System.out.println( “SmallCat mi mi .. “ );
  }
  public static void main( String[] a ) throws Exception
  {
    Cat cat = new SmallCat();
    cat.mi();
  }
}
编译错误



写出下列程序的运行结果

interface Playable {
    void play();
}
interface Bounceable {
    void play();
}
interface Rollable extends Playable, Bounceable {
    Ball ball = new Ball("PingPang");}
class Ball implements Rollable {
    private String name;
    public String getName() {
        return name;
    }
    public Ball(String name) {
        this.name = name;       
    }
   public void play() {
        ball = new Ball("Football");
      
不能再改变ball,它是public fiall static

        System.out.println(ball.getName());
    }
}

写出下列程序的运行结果

class Value{
public int i = 15;
}
public class Test{
public static void main(String argv[]){
       Test t = new Test();
    t.first();
   }
public void first(){
       int i = 5;
       Value v = new Value();
      v.i = 25;
      second(v, i);
      System.out.println(v.i);20   }
public void second(Value v, int i){
      i = 0;
       v.i = 20;
     Value val = new Value();
        v = val;
        System.out.println(v.i + " " + i); 15 0      }
}


写出下列程序的运行结果

class MyThread extends Thread{
public void run(){
System.out.println("MyThread: run()");
}
public void start(){
System.out.println("MyThread: start()");
    }
}
class MyRunnable implements Runnable{
public void run(){
System.out.println("MyRunnable: run()");
    }
public void start(){
System.out.println("MyRunnable: start()");
   }
}
public class MyTest {
public static void main(String args[]){
MyThread myThread  =  new MyThread();
MyRunnable myRunnable = new MyRunnable();
Thread thread  =  new Thread(myRunnable);
myThread.start();
thread.start();
}
}
MyThread: start()
MyRunnable: run()

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics