admin 管理员组文章数量: 1086019
2024年4月27日发(作者:jquery插件react能用吗)
Java试题
1) java程序中,main方法的格式正确的是()。 (选择一项)
a)static void main(String[] args)
b)public void main(String[] args)
c)public static void main(String[]s)
d)public static void main(String[] args)
2) 给定java代码,如下:
public byte count(byte b1,byte b2){
return______;
}
要使用这段代码能够编译成功,横线处可以填入() 。 (选择一项)
a) (byte) (b1-b2)
b) (byte) b1-b2
c) b1-b2
d) (byte) b1/b2
3) 在Java中,在包下定义一个类,要让包下的所有类都可以访问这个类,
这个类必须定义为()。 (选择一项)
a)protected
b)private
c)public
d)friendly
4) 在Java中,下列()语句不能通过编译。 (选择一项)
a) String s= “join”+ “was”+ “here”;
b) String s= “join”+3;
c) int a= 3+5
d) float f=5+5.5;
5) 在Java中下列()方法可以把JFrame的布局管理器设为FlowLayout类型(选择一项)
a)out(new FlowLayout() );
b) out(new FlowLayout() )
c)wLayout()
d)wLayout()
6)给定java代码如下,运行时,会产生()类型的异常。(选择一项)
String s=null;
(“abc”);
a)ArithmeticException
b)NullPointerException
c)IOException
d)EOFException
7) 在java中,()对象可以使用键/值的形式保存数据。 (选择一项)
a)ArrayList
b) HashSet
c) HashMap
d) LinkedList
1
8) 给定如下java代码,编译运行之后,将会输出()。
public class Test{
public staticvoid main(String args[]){
int a=5;
n(a%2==1) ?(a+1) /2:a/2) ;
}
} (选择一项)
a)1
b)2
c)2.5
d)3
9) 以下Java语句中,String str = “123456789”;str =ing(1,3);执行后str中的值为。(选
择一项)
a) “23”
b) “123”
c) “12”
d) “234”
10) 给定如下java代码,以下()代码行编译会报错。(选择一项)
class MyClass{
void myMethod(final int p){
final int il;
final int i2=p;
i1=20;
i2=20;
}
}
a) void my Method(final int p)
b) final int il;
c) final int i2=p
d) il=20
e) i2=20;
11) 给定如下java代码,编译时会在()出现错误。
class Parent{
}
class Child extends Parent{
public static void main(String args[]){
Parent p1=new Child() ;//第一行
Parent p2=new Parent () ;//第二行
Child c1=new Child() ;//第三行
Child c2=new Parent () ;//第四行
}
} (选择一项)
a) 第一行
2
b) 第二行
c) 第三行
d) 第四行
12)给定某java程序的main方法,如下:
public static void main (String[]arg){
( “Hello”+args[1]) ;
}
从命令行传参:people world nation,该程序的运行结果是()。 (选择一项)
a) Hello people
b) Hello world
c) Hello people world nation
d) 运行时出现异常
13) 给定Java代码,如下:
abstract class Shape{
abstract void draw() ;
}
要创建Shape类的子类Circle,以下代码正确的是() (选择二项)
a) class Circle extends Shape{
int draw() {}
}
b) abstract class Circle extends Shape{
}
c) class Circle extends Shape{
void draw() ;
}
d) class Circle extends Shape{
void draw() {}
}
14) 给定如下java代码,编译运行时,结果是()。 (选择一项)
public class Test{
public static void main (String args[]) {
for (int i=0;i<3; i++) {
(i) ;
}
(i) ;
}
}
a) 编译时报错
b) 正确运行,输出012
c) 正确运行,输出123
d) 正确运行,输出0123
15) 给定一个Java程序的方法结构如下;以下方法体实现语句正确的是(
public Integer change( int i) {
}
3
。(选择两项)
)
a) Integer int =new Integer( i) ;
return int;
b) Integer t = f( i) ;
return t;
c) return new Integer( i) ;
d) return i;
16) 在java中,在尝试对null 对象操作时,会产生( )类型的异常。(选择一项)
a) ArithmeticException
b) NullPointerException
c) IOException
d) EOFException
6)
17) Java语言中,String str=”123456789”,n(f(“5”)),输出结果为()。
(选择一项)
a) 6
b) 5
c) 4
d) -1
18) 在java中,已定义两个接口B和C,要定义一个实现这两个接口的类,以下语句正确
的是( ) 。(选择一项)
a) interface A extends B,C
b) interface A implements B,C
c) class A implements B,C
d) class A implements B,implements C
19)给定JAVA代码,如下:
Class Parent{
public void count() {
n(10%3) ;
}
}
public class Test extends Parent{
public void count() {
n(10/3) ;
}
public static void main(String args[]) {
Parent p = new Test() ;
() ;
}
}
运行编译后,输出结果是( )。(选择一项)
a) 1
b) 1.0
c) 3
d) 3.3333333333333335
4
20) 在Java中,下列( )是不合法的赋值语句。(选择一项)
a) float f=1/3;
b) int i=1/3;
c) float f=1*3.0;
d) double f=1.0/3;
21) 利用JAVA SWING 编程,要在当前窗体中显示如下信息提示框,则需要编写的代码
是( )。(选择一项)
a) ssageDialog(null,"请输入登陆名!","提示信
",_OPTION) ;
b) new ssageDialog(null,"请输入登陆名!","提示信
",_OPTION) ;
c) new eDialog(null,"请输入登陆名!","提示信
",_OPTION) ;
d) eDialog(null,"请输入登陆名!","提示信
",_OPTION) ;
22) 给定某java程序的main方法,如下;(选择一项)
public static void main(String [ ]args) {
int i = 0;
n(i++) ;
}
a) 0
b) 1
c) 编译错误
d) 运行时出现异常
23)给定java程序,如下:编译运行,结果是( )。(选择一项)
public class Test{
private static final int counter=10;
public static void main(String[] args) {
n(++counter) ;
}
}
a) 10
b) 11
c) 编译错误
d) 运行时出现异常
24)在JAVA中,要创建一个新目录,要使用( )类的实例。(选择一项)
a) File
b) FileOutputStrean
5
息
息
息
息
c) PrintWriter
d) Dir
25) 在java 中,下列( ) 类不能派生出子类. (选择一项)
a) public class MyClass{ }
b) class MyClass{ }
c) abstract class MyClass{ }
d) final class MyClass { }
26) 在java 中,以下( )命令能够将java源文件编译为类文件 (选择一项)
a) java
b) javaw
c) javac
d) jar
27)在JAVA中,通过调用以下( )方法,可以装载SUN的JDBC-ODBC桥。(选择一
项)
a) new Class() .load(“bcDriber”) ;
b) new Class() .forName(“bcDriver”) ;
c) e(“bcDriver”) ;
d) (“bcDriver”) ;
28) 在JAVA中,要判断D盘下是否存在文件,应该使用以下( )判断语句。(选择
一项)
a) if(new File(“d:”) .exists() = =1)
b) if((“d:”) = =1)
c) if(new File(“d:/”) .exists( ) )
d) if((“d:/))
29) 在JAVA接口中,下列选项里有效的方法声明是( )。(选择二项)
a) public void aMethod( ) ;
b) void aMethod( ) ;
c) static void aMethod( ) ;
d) protected void aMethod( ) ;
30) 给定JAVA代码,如下:编译运行,结果是( )。(选择一项)
public static void main(string[] args)
{
String s;
n(“s=”+s) ;
}
a) 编译错误
b) 编译通过,但出现运行是错误
c) 正常运行,输出s=null
d) 正常运行,输出s=
31) 给定一个java程序的main方法的代码片段如下:假如d 目录下不存在文件,
现运行该程序,下面的结果正确的是( )。 ( 选择一项)
try {
PrintWriter out=new PrintWriter(new FileOutputStream(“d:/”)) ;
6
String name=”chen”;
(name) ;
( ) ;
}
catch(Execption e) {
n(“文件没有发现!“) ;
}
a) 将在控制台上打印:“文件没有发现!”
b) 正常运行,但没有生成文件
c) 运行后生成 ,但该文件中无内容
d) 运行后生成,该文件内容为:chen
32) 在JAVA中,对于PreparedStatement的方法setInt(int i,int x) ,描述正确的是(
(选择一项)
a) 使得第i-1个参数的值设为x
b) 使得第x-1个参数的值设为 i
c) 使得第x个参数的值设为 i
d) 使得第i个参数的值设为 x
33) 给定JAVA程序,如下:
package com;
public class Test{
public void talk( ) { }
protected void walk( ) { }
private void climb( ) { }
private void jump( ) { }
给定Test的子类Test2,代码如下:
Package ;
Import com.*;
Public class Test2 extends Test
{
Public static void main(String[] args)
{
Test2 tt=new Test2( ) ;
//A
}
}
可以在Test2的A处加入的代码是()。(选择二项)
a) ( ) ;
b) ( ) ;
c) ( ) ;
d) ( ) ;
34) 在JAVA语言中,下面变量命名合法的有()。(选择二项)
a) variable123
b) 123varible
c) private
7
。 )
d) variable_123
35)给定一段JAVA代码如下:要打印出list中存储的内容,以下语句正确的是( )。(选
择二项)
ArrayList list = new ArrayList( ) ;
(“a”) ;
(“b”) ;
Iterator it = or( ) ;
a) while(t( ) )
n(( ) ) ;
b) for(int i=0; i<( ) ; i++)
n((i)) ;
c) while(t( ) )
n(( ) ) ;
d) for(int i=0; i<( ) ; i++)
n(it(i)) ;
36) 下列Java Swing 组件,() 是容器组件。(选择二项)
a) JFrame
b) JButton
c) JTextArea
d) JPanel
37) 给定某java 程序的main 方法如下,该程序的运行结果是() (选择一项) 。
pubtic static void main ( String[] args) {
boolean boo=true;
if ( boo== false) {
n ("a") ;
}else {
n ("b") ;
}
a) a b) b c) c d) d
38)下列选项中,不属于Java语言的关键字的是() 。(选择一项)
a) import
b) malloc
c) extends
d) new
39)在JAVA中,() 类提供定位本地文件系统,对文件或目录及其属性进行基本操作。(选择
一项)
a) Filelnputstream
b) FileReader
c) Filewriter
d) File
40)在JAVA中,() 关键字用来终止循环语句。(选择一项)
a) return
b) continue
c) break
8
版权声明:本文标题:Java基础试题及其答案 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1714162072a667926.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论