|

 设有下面两个类的定义:
class Person {
long id; // 身份证号
String name; // 姓名
}
class Student extends Person {
int score; // 入学总分
int getScore(){
re
A:包含关系
B:继承关系
C:关联关系
D:无关系,上述类定义有语法错误
若a的值为3时,下列程序段被执行后,c的值是多少?( )
c = 1;
if ( a>0 ) if ( a>3 ) c = 2; else c = 3; else c = 4;
A:1
B:2
C:3
D:4
下列代码的执行结果是
public class Test
{ public int aMethod()
{
static int i=0;
i++;
System.out.println(i);
}
public static void main(String args[])
{
Test test = new Test();
A:编译错误
B:0
C:1
D:运行成功,但不输出
下面程序的输出结果是什么?
class Foo{
static void change(String s){
s=s.replace('j','l');
}
public static void main(String args[]){
String s="java";
change(s);
System.out.println(s);
}
}
A:lava
B:java
C:编译错误
D:运行时出现异常
65. 已知有下列类的说明,则下列哪个语句是正确的?
public class Test
{
private float f = 1.0f;
int m = 12;
static int n=1;
public static void main(String arg[])
{
Test t = new Test();
}
}
A:t.f;
B:this.n;
C:Test.m;
D:Test.f;
下列语句序列执行后,k的值是( )。
int j=8, k=15;
for( int i=2; i!=j; i++ )
{ j-=2; k++; }
A:15
B:16
C:17
D:18
下列程序的功能是在监控台上每隔一秒钟显示一个字符串“Hello”,能够填写在程序中下划线位置,使程序完整并能正确运行的语句是
public class Test implements Runnable{
public static void main(String args[]){
Test t=new Test();
Thread tt=new Thread(t);
tt.start();
}
public void run(){
for(;;){
try{
A:sleep(1000)
InterruptedException
B:sleep(1000)
RuntimeException
C:Thread.sleep(1000)
RuntimeException
D:Thread.sleep(1000)
InterruptedException
下列语句序列执行后,k 的值是( )。
int x=6, y=10, k=5;
switch( x%y )
{ case 0: k=x*y;
case 6: k=x/y;
case 12: k=x-y;
default: k=x*y-x;
}
A:60
B:54
C:0
D:5
给出下面的接口:
interface A{
int method1(int i);
int method2(int j);
}
下面那个类实现了这个接口,并且不是抽象的?
A:class B implements A{
int method1(){}
int method2(){}
}
B:class B {
int method1(int i){}
int method2(int j){}
}
C:class B implements A{
int method1(int i){}
int method2(int j){}
}
D:class B extends A{
int method1(int i){}
int method2(int j){}
}
给定下面的类:
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.println(ex.str+”and”+ex.ch);
}
public void
A:good and abc
B:good and gbc
C:test ok and abc
D:test ok and gbc
下面的语句的作用是:( )。
Vector MyVector = new Vector(100,50);
A:创建一个数组类对象MyVector,有100个元素的空间,每个元素的初值为50。
B:创建一个向量类对象MyVector,有100个元素的空间,每个元素的初值为50。
C:创建一个数组类对象MyVector,有100个元素的空间,若空间使用完时,以50个元素空间单位递增。
D:创建一个向量类对象MyVector,有100个元素的空间,若空间使用完时,以50个元素空间单位递增。
下列哪个选项的java源文件代码片段是不正确的?
A:package testpackage;
public class Test{ }
B:import java.io.*;
package testpackage;
public class Test{ }
C:import java.io.*;
class Person{ }
public class Test{ }
D:import java.io.*;
import java.awt.*;
public class Test{ }
下面哪一个类可以访问foo包中的所有变量?
package foo;
class a{int c}
class b{private int d}
class c{public int e}
A:class a
B:class b
C:class c
D:都不能
设有下面的一个类定义:
class AA {
static void Show( ){ System.out.println("我喜欢Java!"); }
}
class BB { void Show( ){ System.out.println("我喜欢C++!"); } }
若已经使用AA类创建对象a和BB类创建对象b,则下面哪一个方法调用是正确的:( )
A:a.Show( )
b.Show( )
B:AA.Show( )
BB.Show( )
C:AA.Show( )
b.Show( )
D:a.Show( )
BB.Show( )
下列程序段执行后t5的结果是( )。int t1 = 9, t2 = 11, t3=8;int t4,t5;t4 = t1 > t2 ? t1 : t2+ t1;t5 = t4 > t3 ? t4 : t3;
A:8
B:20
C:11
D:9
下面程序的输出结果是什么?
class Happy {
public static void main(String args[]) {
int i =1;
int j = 10;
do {
if ( i++ < j--)
continue;
} while ( i <5 );
System.out.println ( i+" "+j );
}
}
A:5 5
B:5 4
C:6 4
D:5 6
有下面的类:
public class Example{
static int x[]=new int[15];
public static void main(String args[]){
System.out.println(x[5]);
}
}
下面的那些说法是正确的。
A:编译时出错
B:运行时出错
C:输出0
D:输出null
在程序的源文件开始处有下面一行程序:
package awt;
A:结果是一个编译错误,因为Java已经定义了一个awt包
B:说明这个文件里的所有的类都应该包含在java.awt包里
C:说明这个文件里的所有的类都应该包含在自己定义的awt包里
D:导入你自己定义的awt包里的所有类
下面程序运行后I的结果是什么?
Class sree
{
fun(){
static int I =0;
I++;
}
public static void main(String args[])
{
sree obj=new sree();
obj.fun();
obj.fun();
}
A:编译错误
B:运行时错误
C:1
D:2
给出如下代码:
class Test{
private int m;
public static void fun() {
// some code...
}
}
如何使成员变量m被函数fun()直接访问?
A:将private int m 改为protected int m
B:将private int m 改为 public int m
C:将private int m 改为 static int m
D:将private int m 改为 int m
如果有以下代码,哪几个数字能产生输出 "Test2" 的结果?
Switch(x){
case 1: System.out.println("Test1");
case 2:
case 3: System.out.println("Test2");
break;}
System.out.println("Test3");
}
A:0
B:1
C:2
D:3
String s=”Example String”;
下面哪些语句是正确的?
A:s>>>=3;
B:int i=s.length();
C:s[3]=”x”;
D:String short_s=s.trim();
E:String t=”root”+s;
假定文件名是“Fred.java”,下面哪个是正确的类声明。
A:public class Fred{
public int x = 0;
public Fred (int x){
this.x=x;
}
}
B:public class fred{
public int x = 0;
public Fred (int x){
this.x=x;
}
}
C:public class Fred extends MyBaseClass{
public int x = 0;
}
已知如下代码:
switch (m)
{
case 0: System.out.println("Condition 0");
case 1: System.out.println("Condition 1");
case 2: System.out.println("Condition 2");
case 3: System.out.println("Condition 3");break;
default: System.out.println("Other Condition");
}
当m 的
A:0
B:1
C:2
D:3
E:4
F:以上都不是
下面代码执行后的输出是什么?
outer: for(int i=0;i<3; i++)
inner: for(int j=0;j<2;j++)
{
if(j==1) continue outer;
System.out.println(j+ “ and “+i);
}
A:0 and 0
B:0 and 1
C:0 and 2
D:1 and 0
E:1 and 1
F:1 and 2
G:2 and 0
H:2 and 1
I:2 and 2
选择所有有效的构造函数。
class Happy {
}
}
A:public void Happy(){}
B:public Happy(int c){}
C:protected Happy(){}
D:public int Happy(){}
E:void Happy(){}
已知如下类定义:
class Base {
public Base (){ //... }
public Base ( int m ){ //... }
protected void fun( int n ){ //... }
}
public class Child extends Base{
// member methods
}
如下哪句可以正确地加入子类中?
A:private void fun( int n ){ //...}
B:void fun ( int n ){ //... }
C:protected void fun ( int n ) { //... }
D:public void fun ( int n ) { //... }
已知如下定义:
String s = "story";
下面哪些表达式是合法的?
A:s += "books";
B:char c = s[1];
C:int len = s.length;
D:String t = s.toLowerCase();
针对下面的程序,那些表达式的值是true?
Class Aclass{
private long val;
public Aclass(long v){val=v;}
public static void main(String args[]){
Aclass x=new Aclass(10L);
Aclass y=new Aclass(10L);
Aclass z=y;
long a=10L;
int b=10;
}
}
A:a==b;
B:a==x;
C:y==z;
D:x==y;
E:a==10.0;
你怎样从下面main()的调用中访问单词“kiss”?
java lyrics a kiss is but a kiss
A:args[0]
B:args[1]
C:args[2]
D:args[3]
E:args[4]
F:args[5]
|
|