面向对象程序设计(基于Java)(华东师范大学)中国大学MOOC答案2024完整版WYC

对应课程:点击查看
起止时间:2020-07-06到2020-08-02
更新状态:已完结

第五章 继承、接口和抽象类 第五章 单元测验

1、 现有 public class Parent{ public void change (int x){ } } public class Child extends Parent{ //覆盖父类change方法 }下列哪个声明是正确的覆盖了父类的change方法?

A:protected void change (int x){}
B:public void change(int x, int y){}
C:public void change (int x){}
D:public void change (String s){}
答案: public void change (int x){}

2、 class Ca{ int num = 1; Ca(int num){ this.num = num; System.out.print(this.num); }}class Cb extends Ca{ int num = 2; Cb(int num) { this.num = num; System.out.print(num); } public static void main(String[] args) { Ca a = new Cb(5); }} 运行代码,程序输出结果为:

A:15
B:52
C:51
D:编译报错
答案: 编译报错

3、 下面关于继承的叙述正确的是()

A:Java中一个类只能实现一个接口
B:Java类中只允许单一继承
C:Java中一个类不能同时继承一个类和实现一个接口
D:Java中一个类可继承于多个类
答案: Java类中只允许单一继承

4、 给定下列程序,请选出正确结果。class Cat { Cat (int c) { System.out.print (“cat”+c+” “); } }class SubCat extends Cat { SubCat (int c){ super (5); System.out.print (“cable”); } SubCat() { this (4); } public static void main (String [] args) { SubCat s= new SubCat(); }}

A:cat5
B:cable
C:cat5 cable
D:cable cat5
答案: cat5 cable

5、 下列程序的输出是()。class Other{ public Other () { System.out.print(“Other!”); } } public class Driver1 extends Other { public static void main( String[] args ) { new Driver1(); new Other (); } }

A:Other!
B:Other!Other!
C:Other!Other!Other!
D:编译出错
答案: Other!Other!

6、 请选出以下程序的输出结果class A { public void func1() { System.out.println(“A func1 is calling”); } public void func2() { func1(); }}class B extends A { public void func1() { System.out.println(“B func1 is calling”); } public void func3() { System.out.println(“B func3 is calling”); }}class C { public static void main(String[] args) { A a = new B(); a.func1(); a.func2(); a.func3(); } }

A:A func1 is callingB func3 is calling
B:B func1 is callingB func3 is calling
C:A func1 is callingA func1 is callingB func3 is calling
D:编译错误
答案: 编译错误

7、 请选出以下程序的输出结果public class Child extends People { People father; public Child(String name) { System.out.print(3); this.name = name; father = new People(name + “:F”); } public Child() { System.out.print(4); } public static void main(String[] args) { new Child(“Alice”); }}class People { String name; public People() { System.out.print(1); } public People(String name) { System.out.print(2); this.name = name; }}

A:123
B:132
C:32
D:312
答案: 132

8、 请选出正确答案class Parent { String one, two; public Parent(String a, String b){ one = a; two = b; } public void print(){ System.out.println(one); }}public class Child extends Parent { public Child(String a, String b){ super(a,b); } public void print(){ System.out.println(one + ” to ” + two); } public static void main(String arg[]){ Parent p = new Parent(“south”, “north”); Parent t = new Child(“east”, “west”); p.print(); t.print(); }}

A:Cause error during compilation.
B:south to northeast to west
C:south to northeast
D:southeast to west
答案: southeast to west

9、 请选择正确的输出结果class Guy { public Guy(){ System.out.print(“111,”); }}class Cowboy extends Guy { public Cowboy(){ System.out.print(“222,”); }}class Wrangler extends Cowboy { public Wrangler(){ System.out.print(“333,”); }}public class Greeting2 { public static void main(String[] args) { Guy g1 = new Guy(); Guy g2 = new Cowboy(); Guy g3 = new Wrangler(); }}

A:111,222,333,
B:111,111,222,222,333,
C:111,111,222,111,222,333,
D:编译错误
答案: 111,111,222,111,222,333,

10、 给定以下程序class Pencil { public void write (String content){ System.out.println( “Write”+content); }}class RubberPencil extends Pencil{ public void write (String content){ System.out.println(“Rubber Write”+content); } public void erase (String content){ System.out.println( “Erase “+content); }}执行下列代码的结果是哪项?Pencil p=new Pencil();(( RubberPencil) p).write(“Hello”);

A:Write Hello
B:Rubber Write Hello
C:编译失败
D:运行时抛出异常
答案: 运行时抛出异常

第六章 static、final和常量设计 第六章 static和final测验

1、 下面关于变量及其范围的陈述哪些是错误的

A:实例变量是类的成员变量
B:实例变量用关键字static声明
C:在方法中定义的局部变量在该方法被执行时创建
D:局部变量在使用前必须被初始化
答案: 实例变量用关键字static声明

2、 下列说法错误的是

A:声明为static的方法可以被重写
B:声明为static的方法不可以调用非static变量
C:声明为final的方法可以被重写
D:声明为final的类不可以被继承
答案: 声明为final的方法可以被重写

3、 以下代码class FinalTest{ int num = 1; public static void main(String[] args) { final FinalTest ft = new FinalTest();//1 ft.num = 100;//2 //3 System.out.println(ft.num);//4 }}

A:编译通过,但在//3处加上 ft.num ++; 后编译报错
B:编译通过,但在//3处加上 ft = new FinalTest();; 后编译报错
C:编译不通过,去除//1中的 final 后编译通过
D:编译不通过,删除//2 整行后编译通过
答案: 编译通过,但在//3处加上 ft = new FinalTest();; 后编译报错

4、 下列代码执行结果是class NumTest{ static int id = 1; int id2 = 1; NumTest(int id,int id2){ this.id = id; this.id2 = id2; } void printId(){ System.out.print(id+id2+” “); } public static void main(String[] args) { NumTest a = new NumTest(1,2); NumTest b = new NumTest(2,1); NumTest c = new NumTest(0,0); a.printId(); b.printId(); c.printId(); }}

A:3 3 0
B:1 2 0
C:2 1 0
D:编译报错
答案: 2 1 0

5、 以下代码class FinalTest{ final int num = 1; public static void main(String[] args) { final FinalTest ft = new FinalTest();//1 ft.num = 100;//2 //3 System.out.println(ft.num);//4 }}

A:编译通过,但在//3处加上 ft.num ++; 后编译报错
B:编译通过,但在//3处加上 ft = new FinalTest(); 后编译报错
C:编译不通过,去除//1的 final 后编译通过
D:编译不通过,删除//2 整行后编译通过
答案: 编译不通过,删除//2 整行后编译通过

6、 class NumTest{ final int id = 1; int id2 = 1; NumTest(int id,int id2){ this.id = id; this.id2 = id2; } void printId(){ System.out.print(id+id2+” “); } public static void main(String[] args) { NumTest a = new NumTest(1,2); NumTest b = new NumTest(2,1); NumTest c = new NumTest(0,0); a.printId(); b.printId(); c.printId(); }}

A:3 3 0
B:1 2 0
C:2 1 0
D:编译报错
答案: 编译报错

7、 下列代码执行结果是 class NumTest{ final static int num1 = 1; static int num2 = 1; void printNum1(){ System.out.print(num1+” “); } void printNum2(){ System.out.print(num2+” “); } public static void main(String[] args) { NumTest a = new NumTest(); a.num2 ++; a.printNum1(); NumTest b = new NumTest(); b.printNum2(); }}

A:1 1
B:1 2
C:2 2
D:编译报错
答案: 1 2

8、 下列代码执行结果是class NumTest{ final static int num1 = 1; static int num2 = 1; void printNum1(){ System.out.print(num1+” “); } void printNum2(){ System.out.print(num2+” “); } public static void main(String[] args) { NumTest a = new NumTest(); a.num1 ++; a.printNum2(); NumTest b = new NumTest(); b.printNum1(); }}

A:2 1
B:1 2
C:1 1
D:编译报错
答案: 编译报错

9、 以下代码执行结果是class StaticTest{ static{ System.out.print(“a “); } static{ System.out.print(“b “); } public static void main(String[] args) { StaticTest st1 = new ChildTest(); }} class ChildTest extends StaticTest{ static{ System.out.print(“c “); }}

A:c a b
B:a b c
C:c
D:a b
答案: a b c

10、 以下代码执行结果是class StaticTest{ static{ System.out.print(“a “); } { System.out.print(“b “); } public static void main(String[] args) { StaticTest st2 = new ChildTest(); //main1 System.out.print(“ # ”); //main2 StaticTest st = new StaticTest(); //main3 }} class ChildTest extends StaticTest{ static{ System.out.print(“c “); }}

A:a c b # a b
B:a b c # a b c
C:a c b # b
D:a b c # a b
答案: a c b # b

第六章 static、final和常量设计(续) 期中练习

1、 有如下类定义:public class ClassAndVariables{    public static int x = 8;     public int y = 9; }执行如下代码:ClassAndVariables a = new ClassAndVariables();ClassAndVariables b = new ClassAndVariables();a.y = 5;b.y = 6;a.x = 1;b.x = 2;则a.y, b.y, a.x, b.x的值分别为:

A:5, 6, 1, 2
B:6, 6, 1, 2
C:5, 6, 2, 2
D:6, 6, 2, 2
答案: 5, 6, 2, 2

2、 请阅读以下程序,并写出结果public class ArgumentPassing { public static void changeValue(int a) { a = 10; } public static void changeValue(String s1){ s1 = “def”; } public static void changeValue(StringBuffer s1) { s1.append(“def”); } public static void main(String[] args) { int a = 5; String b = “abc”; StringBuffer c = new StringBuffer(“abc”); changeValue(a); changeValue(b); changeValue(c); System.out.print(a); System.out.print(b); System.out.print(c); }}

A:5abcabc
B:10abcabc
C:10defdef
D:5abcabcdef
答案: 5abcabcdef

3、 下列关于构造方法的叙述中,错误的是

       


注:此答案尚未制作完成,如需购买,可点击下方红字提交表单联系客服更新,更新后可直接在本网页购买答案

点击这里,联系客服更新


为了方便下次阅读,建议在浏览器添加书签收藏本网页

添加书签方法:

1.电脑按键盘的Ctrl键+D键即可收藏本网页

2.手机浏览器可以添加书签收藏本网页

面向对象程序设计(基于Java)(华东师范大学)中国大学MOOC答案2024完整版WYC第1张

面向对象程序设计(基于Java)(华东师范大学)中国大学MOOC答案2024完整版WYC第2张


获取更多MOOC答案,欢迎在浏览器访问我们的网站:http://mooc.mengmianren.com

面向对象程序设计(基于Java)(华东师范大学)中国大学MOOC答案2024完整版WYC第3张

面向对象程序设计(基于Java)(华东师范大学)中国大学MOOC答案2024完整版WYC第4张

注:请切换至英文输入法输入域名,如果没有成功进入网站,请输入完整域名:http://mooc.mengmianren.com/


我们的公众号

打开手机微信,扫一扫下方二维码,关注微信公众号:萌面人APP

本公众号可查看各种网课答案,还可免费查看大学教材答案

点击这里,可查看公众号功能介绍

面向对象程序设计(基于Java)(华东师范大学)中国大学MOOC答案2024完整版WYC第5张


一键领取淘宝,天猫,京东,拼多多无门槛优惠券,让您购物省省省,点击这里,了解详情


干饭人福利,饿了么红包每日领 

面向对象程序设计(基于Java)(华东师范大学)中国大学MOOC答案2024完整版WYC第6张

点击这里,领取饿了么外卖红包