JAVA:面向对象编程测题
上传者:李渊|上传时间:2016-09-17|密次下载
JAVA:面向对象编程测题
面向对象编程
(1)
Given the following Java code: |
class Animal { public String noise () { return "peep"} } public String noise () { return "back"; }
} public String noise () { return "move"; }
} |
A. peep |
(2)
|
Given the following Java code: |
10. |
interface A { public int getValue (); } public int getValue () { return 1; }
} // insert code here
} |
|
A. public void add(C c) { c.getValue(); } |
(3)
Add methods to the Beta class to make it compile correctly. |
class Alpha { public void bar ( int… x ) {} public void bar (int x ) {} } |
public class Beta extends Alpha { place here place here place here } |
Methods |
(4)
Given the following Java code: |
class Test1{ public Test1 foo() { return this; }
} public Test1 foo() { return this; }
} // insert method here
} |
|
(5)
Given the following Java code: |
public class Bootchy{ int bootch; String snootch;
public Bootchy() { this( "snootchy" ); System.out.print( "first " ) ; }
public Boothchy( String snootch ) { this( 420, "snootchy" ); System.out.print( "second " ) ; }
public Bootchy(int bootch, String snootch ) { this.bootch = bootch; this. snootch = snootch; System.out.print( "third " ); }
public static void main(String[] args ) { Bootchy b= new Bootchy (); System.out.print(b.snootch + " " + b.bootch ); }
} |
(6)
|
Given the following Java code: |
09. |
public class Test{ static class A { void process () throws Exception { throw new Exception () ; } }
static class B extends A { void process () { System.out.println( " B" ); } } public static void main (String[ ] args ) { A a = new B (); a.process (); }
} |
|
A. B E. Compilation fails because of an error in line 18. F. Compilation fails because of an error in line 19. |
(7)
|
Given the following Java code: |
10 |
interface Foo {} public static void main(String[] args) { Beta x = new Beta (); // insert code here }
} |
|
A. Alpha a = x; |
(8)
Given the following Java code: |
public class Person{ private String name, comment; private int age; public Person(String n, int a, String c) { name = n; age = a; comment = c; } public Boolean equals(Object o){ if (! (o instanceof Person)) return false; Person p = (Person)o; return age == p.age && name.equals(p.name); }
} |
A. return super.hashCode(); |
(9)
|
Given the following code: |
01. |
public class Person{ private String name; public Person (String name){ this.name = name; } public Boolean equals(Person p){ return p.name.equals(this.name); }
} |
|
A. The equals method does NOT properly override the object Object.equals method. B. Compilation fails because the private attribute p.name cannot be accessed in line 5. C. To work correctly with hash-based data structures, this class must also implement the hashCode method. D. When adding Person objects to java.util. Set collection, the equals method in line 4 will prevent duplicates. |
(10)
Place the Output Options in the Actual Output Sequence to indicate the output from this code: |
||||||||
class Alpha { public void foo(String... args) { System.out.print("Alpha:foo ");
} System.out.print("Alpha:bar "); }
} public void foo(String a) { System.out.print("Beta:foo ");
} System.out.print("Beta:bar ");
}
Alpha a = new Beta(); }
}
|
(11)
|
Given the following Java code: |
1. |
public interface A { public void doSomething(String thing); } |
1. |
public class AImp1 implements A { public void doSomething(String msg) {} } |
1. |
public class B { public A doit() { // more code here }
public String execute() { // more code here } } |
1. |
public class C extends B { public AImp1 doit() { // more code here }
public Object execute() { // more code here }
} |
|
B. Compilation of class C will fail because of an error int line 2. C. Compilation of class C will fail because of an error int line 6. D. Compilation of AImpl will fail because of an error in line 2. |
(12)
Given the following Java code: |
||
class A { String name = "A" ; String getName() { return name; } String greeting() { return "class A" ; }
} String name = "B" ; String greeting() { return "class B" ; }
} public static void main(String[] args) { A a = new A() ; A b = new B() ; System.out.println(a.greeting () + " has name " + a.getName () ) ; System.out.println(b.greeting () + " has name " + b.getName () ) ; }
}
|
(13)
|
Given the following Java code: |
1. |
class SuperClass { public A getA() { return new A() ; }
} public B getA() { return new B(); }
} |
|
A. Compilation will succeed if A extends B B. Compilation will succeed if B extends A C. Compilation will always fail because of an error in line 7 D. Compilation will always fail because of an error in line 8 |
(14)
|
Given the following Java code: |
1. |
class Pizza { java.util.ArrayList toppings; public final void addTopping(String topping) { toppings.add(topping); }
} public void addTopping(String topping) { System.out.println("Cannot and Uoppings"); } public static void main(String[] args) { Pizza pizza = new PepperoniPizza(); Pizza.addTopping("Mushrooms"); }
} |
|
A. Compilation fails |
(15)
|
Given the following Java code: |
10. |
interface A { void x ();
} public void x () {} public void y () {}
} public void x () {}
} |
20. |
java.util.List <A> list = new java.util.ArrayList<A> (); list.add(new B ()); list.add(new C ()); for (A a : list ) { a.x(); a.y(); }
|
|
A. The code runs with no output C. Compilation fails because of an error in line 20 D. Compilation fails because of an error in line 21 E. Compilation fails because of an error in line 23 F. Compilation fails because of an error in line 25 |
(16)
|
Given the following Java code: |
10. |
class One { void foo() {}
} // insert method here
} |
|
A. int foo(){/*more code here */} |
(17)
Which two statements are true about the hashCode method? (Choose two) |
A. The hashCode method for a given class can be used to test for object equality and object inequality for that class. (hashCode method |
(18)
Given the following Java code: |
class SomeException: |
class A: public void doSomething() {} } |
class B: public void soSomething() throws SomeException {}
} |
B. Compilation of both classes will succeed. D. Compilation of class B will fail, Compilation of class A will succeed. |
下载文档
热门试卷
- 2016年四川省内江市中考化学试卷
- 广西钦州市高新区2017届高三11月月考政治试卷
- 浙江省湖州市2016-2017学年高一上学期期中考试政治试卷
- 浙江省湖州市2016-2017学年高二上学期期中考试政治试卷
- 辽宁省铁岭市协作体2017届高三上学期第三次联考政治试卷
- 广西钦州市钦州港区2016-2017学年高二11月月考政治试卷
- 广西钦州市钦州港区2017届高三11月月考政治试卷
- 广西钦州市钦州港区2016-2017学年高一11月月考政治试卷
- 广西钦州市高新区2016-2017学年高二11月月考政治试卷
- 广西钦州市高新区2016-2017学年高一11月月考政治试卷
- 山东省滨州市三校2017届第一学期阶段测试初三英语试题
- 四川省成都七中2017届高三一诊模拟考试文科综合试卷
- 2017届普通高等学校招生全国统一考试模拟试题(附答案)
- 重庆市永川中学高2017级上期12月月考语文试题
- 江西宜春三中2017届高三第一学期第二次月考文科综合试题
- 内蒙古赤峰二中2017届高三上学期第三次月考英语试题
- 2017年六年级(上)数学期末考试卷
- 2017人教版小学英语三年级上期末笔试题
- 江苏省常州西藏民族中学2016-2017学年九年级思想品德第一学期第二次阶段测试试卷
- 重庆市九龙坡区七校2016-2017学年上期八年级素质测查(二)语文学科试题卷
- 江苏省无锡市钱桥中学2016年12月八年级语文阶段性测试卷
- 江苏省无锡市钱桥中学2016-2017学年七年级英语12月阶段检测试卷
- 山东省邹城市第八中学2016-2017学年八年级12月物理第4章试题(无答案)
- 【人教版】河北省2015-2016学年度九年级上期末语文试题卷(附答案)
- 四川省简阳市阳安中学2016年12月高二月考英语试卷
- 四川省成都龙泉中学高三上学期2016年12月月考试题文科综合能力测试
- 安徽省滁州中学2016—2017学年度第一学期12月月考高三英语试卷
- 山东省武城县第二中学2016.12高一年级上学期第二次月考历史试题(必修一第四、五单元)
- 福建省四地六校联考2016-2017学年上学期第三次月考高三化学试卷
- 甘肃省武威第二十三中学2016—2017学年度八年级第一学期12月月考生物试卷
网友关注
- 2011年6月广东学业水平考试物理试题及参考答案
- 第四章 综合指标
- 学会等待_静等花开石喜扣
- 矛盾是事物发展的源泉和动力教学设计
- 2015年江苏省学业检测地理模拟试卷
- 本科十佳寝室申请书
- 高一优秀学生的入党志愿书
- 源远流长的中华文化教案
- 2015年江苏省学业检测数学模拟试卷一
- 如何打好羽毛球
- 高中期末考差了的检讨书
- 2015年高中入团申请书范文
- 2011年6月广东学业水平考试地理试题及参考答案
- 高中生入团申请书范本参考
- 给安静乖巧的中等生插上飞翔的翅膀__我的德育案例
- 高三学生考试不理想的检讨书
- 第27个教师节献词
- 《信息技术基础》信息安全导学案
- 新时代的劳动者学案
- 小谷精草
- 2015年高中入团申请书600字
- 读“走进高中信息技术教学现场”有感3
- 班刊第4期---离了手机活得了吗?
- 广东省电子信息技工学校(第四单元)
- 无限极增建口服液营销策划书
- 读“走进高中信息技术教学现场”有感2
- 2015年江苏省学业检测音乐模拟试卷
- 新闻点评答案
- 读“走进高中信息技术教学现场”有感1
- 用发展的观点看问题教案
网友关注视频
- 北师大版数学四年级下册第三单元第四节街心广场
- 苏教版二年级下册数学《认识东、南、西、北》
- 19 爱护鸟类_第一课时(二等奖)(桂美版二年级下册)_T502436
- 化学九年级下册全册同步 人教版 第25集 生活中常见的盐(二)
- 人教版二年级下册数学
- 沪教版牛津小学英语(深圳用) 四年级下册 Unit 12
- 【部编】人教版语文七年级下册《逢入京使》优质课教学视频+PPT课件+教案,辽宁省
- 北师大版小学数学四年级下册第15课小数乘小数一
- 沪教版牛津小学英语(深圳用)五年级下册 Unit 1
- 二年级下册数学第一课
- 冀教版小学数学二年级下册第二周第2课时《我们的测量》宝丰街小学庞志荣
- 【部编】人教版语文七年级下册《老山界》优质课教学视频+PPT课件+教案,安徽省
- 沪教版牛津小学英语(深圳用) 四年级下册 Unit 8
- 沪教版八年级下册数学练习册一次函数复习题B组(P11)
- 沪教版牛津小学英语(深圳用) 五年级下册 Unit 7
- 三年级英语单词记忆下册(沪教版)第一二单元复习
- 沪教版八年级下册数学练习册21.4(1)无理方程P18
- 青岛版教材五年级下册第四单元(走进军营——方向与位置)用数对确定位置(一等奖)
- 外研版英语七年级下册module3 unit1第二课时
- 【部编】人教版语文七年级下册《泊秦淮》优质课教学视频+PPT课件+教案,湖北省
- 《空中课堂》二年级下册 数学第一单元第1课时
- 冀教版小学英语四年级下册Lesson2授课视频
- 苏科版八年级数学下册7.2《统计图的选用》
- 第12章 圆锥曲线_12.7 抛物线的标准方程_第一课时(特等奖)(沪教版高二下册)_T274713
- 二次函数求实际问题中的最值_第一课时(特等奖)(冀教版九年级下册)_T144339
- 第五单元 民族艺术的瑰宝_15. 多姿多彩的民族服饰_第二课时(市一等奖)(岭南版六年级上册)_T129830
- 沪教版八年级下次数学练习册21.4(2)无理方程P19
- 飞翔英语—冀教版(三起)英语三年级下册Lesson 2 Cats and Dogs
- 人教版历史八年级下册第一课《中华人民共和国成立》
- 冀教版英语五年级下册第二课课程解读
精品推荐
- 2016-2017学年高一语文人教版必修一+模块学业水平检测试题(含答案)
- 广西钦州市高新区2017届高三11月月考政治试卷
- 浙江省湖州市2016-2017学年高一上学期期中考试政治试卷
- 浙江省湖州市2016-2017学年高二上学期期中考试政治试卷
- 辽宁省铁岭市协作体2017届高三上学期第三次联考政治试卷
- 广西钦州市钦州港区2016-2017学年高二11月月考政治试卷
- 广西钦州市钦州港区2017届高三11月月考政治试卷
- 广西钦州市钦州港区2016-2017学年高一11月月考政治试卷
- 广西钦州市高新区2016-2017学年高二11月月考政治试卷
- 广西钦州市高新区2016-2017学年高一11月月考政治试卷
分类导航
- 互联网
- 电脑基础知识
- 计算机软件及应用
- 计算机硬件及网络
- 计算机应用/办公自动化
- .NET
- 数据结构与算法
- Java
- SEO
- C/C++资料
- linux/Unix相关
- 手机开发
- UML理论/建模
- 并行计算/云计算
- 嵌入式开发
- windows相关
- 软件工程
- 管理信息系统
- 开发文档
- 图形图像
- 网络与通信
- 网络信息安全
- 电子支付
- Labview
- matlab
- 网络资源
- Python
- Delphi/Perl
- 评测
- Flash/Flex
- CSS/Script
- 计算机原理
- PHP资料
- 数据挖掘与模式识别
- Web服务
- 数据库
- Visual Basic
- 电子商务
- 服务器
- 搜索引擎优化
- 存储
- 架构
- 行业软件
- 人工智能
- 计算机辅助设计
- 多媒体
- 软件测试
- 计算机硬件与维护
- 网站策划/UE
- 网页设计/UI
- 网吧管理