Java面向对象试题
1) 在Java中,如果父类中的某些方法不包含任何逻辑,并且需要有子类重写,应该使用( )关键字来申明父类的这些方法。(选择一项)
a) Final
b) Static
c) Abstract
d) Void
2) 给定两个java程序,如下:
public interface Face{
int counter = 40;
}
public class Test implements Face{
private static int counter;
public static void main(String[]args){
;
}
}
Test.java 的编译运行结果是( )。(选择一项)
a) 40
b) 41
c) 0
d) 1
3) 给定java代码,如下:
public class Test{
static int i;
public int aMethod( ){
i++;
return i;
}
public static void main(String [] args){
Test test = new Test( );
test.aMethod( );
));
}
}编译运行后,输出结果是( )。(选择一项)
a) 0
b) 1
c) 2
d) 3
4) 给定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( ){}
}
5) 给定java代码,如下:
class Parent{
public void count( ){
;
}
}
public class Test extends Parent{
public void count(int i){
;
}
public static void main(String[]args){
Parent p = new Test( );
p.count(3);
}
}
编译运行,结果是( )。(选择一项)
a) 1
b) 3
c) 3.3333335
d) 编译错误
6) 给定java程序Test.java,如下:
import ;
private class Testing extends ArrayList{
private void aMethod( ){
}
}
public class Test extends Testing{
}
现在该程序编译无法通过,错误原因是 ( ) (选择一项)
a) ArrayList不能被继承
b) 一个Test.java文件中不能声明两个类
c) Test的继承语法有错误
d) Testing不能被声明为private
7) 给定java程序,如下:
public class Test{
private static final int counter=10;
public static void main(String [] args){
;
}
}
编译运行Test.java,结果是 ( ) (选择一项)
a) 10
b) 11
c) 编译错误
d) 运行时出现异常
8) 在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
9) 给定一个Java程序代码,如下:
public class Test{
int count = 9;
public void count1(){
int count =10;
"count1="+count);
}
public void count2(){
"count2="+count);
}
public static void main(String args[]){
Test t=new Test();
t.count1();
t.count2();
}
行编译后,输出结果是()。(选择一项)
a) count1=9
count2=9
b) count1=10
count2=9
c) count1=10
count2=10
d) count1=9
count2=10
10) 在JAVA中 ,com包中某类的方法使用下列( )访问修饰符修饰后,可以被com.db包中的子类访问,但不能被com.db中其他类访问。(选择一项)
a) Private
b) protecte0
c) Public
d) Fridndly
11) 给定如下 java 代码, 以下()修饰符可以填入下划线处。(选择二项)
class Parent{
protected void eat(){}
}
class Child extends Parent{
_________ void eat(){}
}
a) Protected
b) Private
c) 什么也不填
d) Public
12) 在Java中,下面关于抽象类的描述正确的是()。(选择两项)
a) 抽象类可以被实例化
b) 如果一个类中有一个方法被声明为抽象的,那么这个类必须是抽象类
c) 抽象类中的方法必须都是抽象的
d) 声明抽象类必须带有关键字abstract
13) 给定如下Java代码,以下()方法可以加入Child类中。(选择两项)
Public class Parent{
int change(){…}
}
Class Child extends Parent{
}
a) public int change(){}
b) int chang(int i){}
c) private int change(){}
d) abstract int change(){}
14) 在java中,在定义类时加上修饰符()可以实现该类不能被实例化。(选择一项)
a) Final
b) Public
c) Private
d) Abstract
15) 在java中,下面()的陈述是正确的。(选择二项)
a) 私有方法不能被重载
b) 静态方法能被重载
c) 公有方法被重写后的访问修饰符可以变成private
d) 一个被重写的方法不能抛出一个在基类中不被检查的异常
16) 分析下面的java代码输出结果为()。(选择一项)
Class Point{
Int x,y;
Point(int x,int y){
This.x=x;
This.y=y;
}
Public ststic void main(String[] args){
Point pt1,pt2;
Pt1=new Pint (3,3);
Pt2=new Pint(4,4);
;
}
}
a) 6
b) 34
c) 8
d) 7
17) 在java中,以下程序的输出结果是()。(选择一项)
Class Point
{
Int x;
Boolean y;
Void output()
{
;
;
}
Public static void main(String[] args)
{
Piont pt =new Point();
Pt.output();
}
}
a) 运行错误
b) 0
Ture
c) 0
False
d) 0
0
18) 给定java代码如下,编译运行结果是()。(选择一项)
public class Test extends Parent{
public int count(){
return 1%9;
}
public static void main(String[] args){
;
}
}
a) 编译错误
b) 运行时出现例外
c) 正常运行,输出1
d) 正常运行,输出0
19) 1、在Java中,如果父类中的某些方法不包含任何逻辑,并且需要有子类重写,应该使用( )关键字来申明父类的这些方法。(选择一项)
a) final
b) static
c) abstract
d) void
20) 在Java接口中,下列选项里有效的方法声明是()(选择二项)
a) public void aMethod();
b) void aMethod();
c) static void aMethod();
d) protected void aMethod();
21) 给定java代码,如下:String s=null;
s.concat(“abc”); 运行时,会产生()类型的异常。(选择一项)
a) ArithmeticException
b) NullPointerException
c) IOException
d) EOFException
22) 在java中,下面捕获异常的语句正确的是()。(选择二项)
a) try{
}finally{
}
b) try{}
c) try{
try{}
d) try{
try{
}finally{}
}catch(Exception ex){}
23) 给定一段Java代码,如下:运行后,输出结果将是() (选择一项)
public class Test
{
public static void main(String []args)
{
int a[] = {0,1,2,3,4};
int sum = 0;
try
{
for (int i=1;i<6;i++)
{
sum = wum + a[i];
}
"sum="+sum);
}
catch (ArrayIndexOutOfBoundsException e)
{
"数组越界");
}
Finally
{
"程序结束");
}
}
}
a) sum = 10
程序结束
b) sum = 10
c) 数组越界
程序结束
d) 数组越界
24) 给定java代码,如下:编译运行,结果是()(选择一项)
public static void main (String [] args){
String s;
;
}
a) 编译错误
b) 编译通过,但出现运行时错误
c) 正常运行,输出s=null
d) 正常运行,输出s=
25) 关于Java的异常处理,以下说法正确的是()。(选择一项)
a) 任何可能引发Error类异常的语句必须封装在try块中
b) 任何可能引发Exception异常的语句必须封装在try块中
c) 任何可能引发RuntimeException异常的语句必须封装在try块中
d) 正常情况下,程序无法捕获Error类的异常
26) 给定java代码,如下,编译运行后,结果是 ( )。 (选择一项)
public class Test{
static String s;
publis static void main(String args[ ]){
char c=s.charAt(0);
;
}
}
a) 编译错误
b) 运行期异常,异常类型为 NullpointerException
c) 运行期异常,异常类型为 ArithmeticExceptioin
d) 运行正常,但无输出内容
27) 在java 的异常处理中,用户自定义的异常类应该是()的子类。(选择一项)
a) Exception
b) Throwable
c) Error
d) RuntimeException
28) 给定入下JAVA代码,运行结束后,控制台上将输出()。(选择一项)
public class Test{
public static String output=””;
public static void foo(int i){
try{
Output+=”1”;
}
catch(Excepion e){
Output+=”2”;
}
finally{
Output+=”3”;
}
Output+=”4”;
}
}
public static void main(String args[]){
foo(0);
;
}
a) 1234
b) 134
c) 124
d) 13
29) 在Java中,出现算术错误时,会产生()类型的异常。(选择一项)
a) ArithmeticException
b) NullPointerException
c) IOException
d) EOFException
30) 给定java代码如下,运行时会产生()类型的异常(选择一项)
String s=null;
s.concat(“abc”);
a) NullPointerException
b) IOException
c) EOFException
d) ArithmeticException