C.编译错误:b.g(new ClassA()) D.以上都不对
31、下列类的声明中不合法的是 。 A.class People(){?} C.class A{?}
B.class 植物{?} D.public class 共有类{?}
32、能作为类的修饰符, 也能作为类成员的修饰符的是 。 A.public
B.extends
C.Float
D.static
33、试完成下述程序片段 。 public class Point{ int x,y; public Point(int x,int y){ ( )=x; ( )=y; } ...... }
A.Point.x Point.y C.super.x super.y
B.this.x this.y D.无解
34、在JAVA 中,下列说法正确的是: 。
A.一个子类可以有多个父类,一个父类也可以有多个子类 B.一个子类可以有多个父类,但一个父类只可以有一个子类 C.一个子类只可以有一个父类,但一个父类可以有多个子类 D.上述说法都不对
35、Father和Son是两个java类,下列哪一选项正确的标识出Father是Son的父类? A.class Son implements Father C.class Father extends Son
B.class Father implements Son D.class Son extends Father
36、重载指的是方法具有相同的名字,但这些方法的参数必须不同。下列哪种说法不属于方法参数的不同 。 A.形式参数的个数不同。 C.形式参数的名字不同。
B.形式参数的类型不同。
D.形式参数类型的排列顺序不同。
37、下列有关抽象类与接口的叙述中正确的是哪一个 。 A.抽象类中必须有抽象方法,接口中也必须有抽象方法 B.抽象类中可以有非抽象方法,接口中也可以有非抽象方法
C.含有抽象方法的类必须是抽象类,接口中的方法必须是抽象方法 D.抽象类中的变量定义时必须初始化,而接口中不是 38、从下列程序中你发现了几处错误 。 abstract class A{ abstract void f(){};
public abstract void k(); }
class B extends A{ protected void f(){ }
void k(){ System.out.print(\ }
public static void main(String[] args) { A a=new A(); a.f(); a.k(); } } A.1
B.2
C.3
D.4
39、关于接口的定义和实现,以下描述正确的是 。 A.接口定义的方法只有定义没有实现
B.接口定义中的变量都必须写明final和static
C.如果一个接口由多个类来实现,则这些类在实现该接口中的方法时采用统一的代码
D.如果一个类实现接口,则必须实现该接口中的所有方法,但方法未必申明为public
三、阅读程序题
1、写出运行结果: 。 public class Computer{ String mainbord,cpu; public Computer(String s1,String s2){ mainbord=s1; cpu=s2; } public static void main(String[]args){
} }
Computer c=new Computer(\华硕\
System.out.println(\
2、写出运行结果: 。 public class ExamA {
private static int arr[] = new int[5]; public static void main(String args[]) { for(int i=arr.length-1;i>=0;i--) arr[i] = 2*i+1; String output = \ int sum = 0;
for(int i=0;i
output += \ }
output += \
System.out.println(output); System.exit(0); } }
3、写出运行结果: 。
public class Person{ String name; int age;
public Person(String name,int age){ this.name=name; this.age=age; }
public static void main(String[]args){ Person c=new Person(\ System.out.println(c.name+\} }
4、写出运行结果: 。
public class abc{
public static void main(String args[ ]) {
SubSubClass x = new SubSubClass(10 , 20 , 30); x.show(); } }
class SuperClass{
int a,b;
SuperClass(int aa , int bb){
a=aa; b=bb; }
void show( ){
System.out.println(\ b=\ } }
class SubClass extends SuperClass{
int c;
SubClass(int aa,int bb,int cc){ super(aa,bb);
c=cc; } }
class SubSubClass extends SubClass{ int a;
SubSubClass(int aa,int bb,int cc){
super(aa,bb,cc); a=aa+bb+cc; }
void show(){
System.out.println(\ b=\} }
5.下面是一个类的定义,请将其补充完整 class ______{ String name; int age;
Student(______ name, int a){ _____.name=name; age=a; } }
6.下面是一个类的定义,请将其补充完整
class ______{ String s;
______ int a=3; A(String s){ this.s=s; }
static int getA(){
c=\
}
}
return a;
四、编程题
1.按要求编写一个Java应用程序:
(1)定义一个接口CanCry,描述会吼叫的方法public void cry()。
(2)分别定义狗类(Dog)和猫类(Cat),实现CanCry接口。实现方法的功能分别为:打印输出“我是狗,我的叫声是汪汪汪”、“我是猫,我的叫声是喵喵喵”。
(3)定义一个主类G,
①定义一个void makeCry(CanCry c)方法,其中让会吼叫的事物吼叫。 ②在main方法中创建狗类对象(dog)、猫类对象(cat)、G类对象(g),用
g调用makecry方法,让狗和猫吼叫。 2、编写一个Java程序,并满足如下要求:
1)编写一个Car类,具有:
属性:品牌(mark)——String类型 功能:驾驶(void drive( ))
2)定义Car类的子类SubCar,具有:
属性:价格(price)、速度(speed)——int型
功能:变速(void speedChange(int newSpeed)),把新速度赋给speed
3)定义主类E,在其main方法中创建SubCar类的两个对象:aodi和benchi的对
象并测试其对象的特性。
4)输出效果如下:
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库《Java面向对象编程》练习题(4)在线全文阅读。
相关推荐: