Lab Report

Caution

  • Must be original works, to prohibit any copying or plagiarism.

一、Experimental Purposes and Requirements

  1. to learn Exception
  2. to learn Text I/O.

二、 Experimental Contents

According to the the textbook,give a detailed reasong analysis of the every exercise in the Lab08(assignment_1)-chapter12 on platform of course.zucc.edu.cn.

For example:

What exception type does the following program throw?

public class Test {public static void main(String[] args) {System.out.println(1 / 0);}
}

A. ArithmeticException

B. ClassCastException

C. ArrayIndexOutOfBoundsException

D. StringIndexOutOfBoundsException

E. No exception

Sample answer

According to the content of “chapter 12.3 Exception type” and 12.2 Exception-Handling Overview,

The words which can best describe the reason is “XXXXXXXX”.

(NOTE, XXXXX MEANS THE ORIGINAL WORDS FROM THE TEXT.)

三、Please show your questions analysis, code and results.

1、Analyze the following code.

class Test {public static void main(String[] args) {    StringBuilder strBuf = new StringBuilder(4);   strBuf.append("ABCDE");    System.out.println("What's strBuf.charAt(5)? " + strBuf.charAt(5));  }
}

A.The program has a runtime error because because the buffer’s capacity is 4, but five characters “ABCDE” are appended into the buffer.

B.The program has a compilation error because you cannot specify initial capacity in the StringBuilder constructor.

C.The program compiles and runs fine.

D.The program has a runtime error because the length of the string in the buffer is 5 after “ABCDE” is appended into the buffer. Therefore, strBuf.charAt(5) is out of range.

According to the content of “10.11.2 The toString, capacity, length, setLength, and charAt Methods”, The words which can best describe the reason is

The charAt(index) method returns the character at a specific index in the string builder. The index is 0 based. The first character of a string builder is at index 0, the next at index 1, and so on. The index argument must be greater than or equal to 0, and less than the length of the string builder.

2、Analyze the following code.

class Test {public static void main(String[] args) {String s;System.out.println("s is " + s);}
}

A.The program has a compilation error because s is not initialized, but it is referenced in the println statement.

B.The program has a runtime error because s is null in the println statement.

C.The program has a runtime error because s is not initialized, but it is referenced in the println statement.

D.The program compiles and runs fine.

According to the content of “2.5 Variables”, The words which can best describe the reason is

For now, all you need to know is that a variable must be declared and initialized before it can be used.

3、Object-oriented programming allows you to derive new classes from existing classes. This is called ——.

A.generalization

B.abstraction

C.inheritance

D.encapsulation

According to the content of “chapter 12.3 Exception type” and 12.2 Exception-Handling Overview, The words which can best describe the reason is

Inheritance enables you to define a general class (i.e., a superclass) and later extend it to more specialized classes (i.e., subclasses).

4、Polymorphism means——

A.that a variable of supertype can refer to a subtype object

B.that a class can extend another class

C.that data fields should be declared private

D.that a class can contain another class

According to the content of “11.7 Polymorphism”, The words which can best describe the reason is

In simple terms, polymorphism means that a variable of a supertype can refer to a subtype object.

5、What is the output of the following code?

public class Test {public static void main(String[] args) {new Person().printPerson();new Student().printPerson();}
}class Student extends Person {private String getInfo() {return "Student";}
}class Person {private String getInfo() {return "Person";}public void printPerson() {System.out.println(getInfo());}
}

A.Person Student

B.Stduent Student

C.Person Person

D.Student Person

According to the content of “11.2 Superclasses and Subclasses”, The words which can best describe the reason is

TheCircle class inherits all accessible data fields and methods from the GeometricObject class. In addition, it has a new data field, radius, and its associated getter and setter methods. The Circle class also contains the getArea(), getPerimeter(), and getDiameter() methods for returning the area, perimeter, and diameter of the circle.

6、Which statements are most accurate regarding the following classes?

class A {private int i;protected int j;
}class B extends A {private int k;protected int m;// some methods omitted
}

A.In the class B, an instance method can only access i, j, k, m.

B.In the class B, an instance method can only access j, m.

C.In the class B, an instance method can only access k, m.

D.In the class B, an instance method can only access j, k, m.

According to the content of “11.2 Superclasses and Subclasses”, The words which can best describe the reason is

The Rectangle class inherits all accessible data fields and methods from the GeometricObject class.

At the same time, private variables in the parent class will not be called.

7、What is the output of running class Test?

public class Test {public static void main(String[] args) {new Circle9();}
}public abstract class GeometricObject {protected GeometricObject() {System.out.print("A");}protected GeometricObject(String color, boolean filled) {System.out.print("B");}
}public class Circle9 extends GeometricObject {/** No-arg constructor */public Circle9() {this(1.0);System.out.print("C");}/** Construct circle with a specified radius */public Circle9(double radius) {this(radius, "white", false);System.out.print("D");}/** Construct a circle with specified radius, filled, and color */public Circle9(double radius, String color, boolean filled) {super(color, filled);System.out.print("E");}
}

A.CBAE

B.ABCD

C.AEDC

D.BACD

E.BEDC

According to the content of “11.3 Using the super Keyword”, The words which can best describe the reason is

The keyword super refers to the superclass and can be used to invoke the superclass’s methods and constructors.

8、A subclass of a non-abstract class must be non-abstract.

A.false

B.true

C.101

D.99

According to the content of “13.2.2 Interesting Points about Abstract Classes”, The words which can best describe the reason is

A subclass can be abstract even if its superclass is concrete. For example, the Object class is concrete, but its subclasses, such as GeometricObject, may be abstract.

9、An abstract class can be extended.

A.true

B.false

According to the content of “13.2.2 Interesting Points about Abstract Classes”, The words which can best describe the reason is

An abstract method cannot be contained in a nonabstract class. If a subclass of an abstract superclass does not implement all the abstract methods, the subclass must be defined as abstract. In other words, in a nonabstract subclass extended from an abstract class, all the abstract methods must be implemented. Also note that abstract methods are nonstatic.

10、At least one method in an abstract class must be abstract.

A.false

B.true

According to the content of “13.2.2 Interesting Points about Abstract Classes”, The words which can best describe the reason is

A class that contains abstract methods must be abstract. However, it is possible to define an abstract class that doesn’t contain any abstract methods. In this case, you cannot create instances of the class using the new operator. This class is used as a base class for defining subclasses.

ZUCC_Object Oriented Programming_Lab09_assignmentCourseZucc_chapter12相关推荐

  1. ZUCC_Object Oriented Programming_Lab01 Introduction to Java

    感谢LDingHui同学提供的代码 Lab Report 01 Note: All your lab reports should be uploaded to BB before the deadl ...

  2. ZUCC_Object Oriented Programming_Lab09 Inheritance and polymorphism

    Lab Report 09 Note: All your lab reports should be uploaded to BB before the deadline. Caution Must ...

  3. ZUCC_Object Oriented Programming_Lab06 Objects and Classes

    Lab Report 06 Note: All your lab reports should be uploaded to BB before the deadline. Caution l Mus ...

  4. Java OOP(Object Oriented Programming)个人理解及总结

    面向对象编程(Object Oriented Programming,OOP,面向对象程序设计) 其三大特征:封装,继承,多态: 封装:解决数据的安全问题. 继承:解决代码的重用问题. 多态:解决程序 ...

  5. SIFT和SURF的替换算法——ORB (Oriented FAST and Rotated BRIEF 快速定向和旋转)

    SIFT和SURF的替代算法--ORB (Oriented FAST and Rotated BRIEF 快速定向和旋转 1. 效果图 2. 源码 参考 1. 用于关键点检测和描述的SIFT(Scal ...

  6. The Proposal of Service Oriented Data Mining System for Solving Real-Life Classification--阅读笔记

    The Proposal of Service Oriented Data Mining System for Solving Real-Life Classification and Regress ...

  7. Histogram of Oriented Gridients(HOG) 方向梯度直方图

    from: Histogram of Oriented Gridients(HOG) 方向梯度直方图 Histogram of Oriented Gridients,缩写为HOG,是目前计算机视觉.模 ...

  8. matlab intergral,matlab學習:人臉識別之HOG(Histograms of Oriented Gradients)

    HOG descriptors 是應用在計算機視覺和圖像處理領域,用於目標檢測的特征描述器.這項技術是用來計算局部圖像梯度的方向信息的統計值.這種方法跟邊緣方向直方圖(edge orientation ...

  9. Python编程基础:第三十九节 面向对象编程Object Oriented Programming

    第三十九节 面向对象编程Object Oriented Programming 前言 实践 前言 到目前为止我们都是函数式编程,也即将每一个功能块写为一个函数.其实还有一种更常用的编程方式被称为面向对 ...

最新文章

  1. 通俗易懂的sys.argv[]的用法
  2. mysql 语法积累
  3. 5 华为兼容性 双指缩放_华为EMUI10“滚屏翻译”之背后的学问
  4. Eclipse配置自动提示(eclipse设置代码API自动出现)
  5. 为什么男性比女性死得更早,心疼一秒钟!
  6. 使用Easy Duplicate Photo Finder for Mac如何查找重复的图片?
  7. 秒杀场景下MySQL的低效原因和改进
  8. VTD-传感器使用小结
  9. GoF设计模式——单例模式(C++实现)
  10. linux 下librtmp源码,linux下基于libRTMP的接收流媒体的程序
  11. 详解网易有道AI战略,智能硬件、教育、办公三大解决方案
  12. 2021-03-26 大数据技术对企业管理的影响和应用前景分析
  13. 网络基础该从哪开始补?这36张图,一次性理清
  14. 区块链普惠云签扶持计划 京东数科助力中小企业复工复产
  15. 2019.11.4 英语学习
  16. 仿造网易云音乐轮播图
  17. 安全态势感知系统java_代码分析平台CodeQL学习手记(十三) - 嘶吼 RoarTalk – 回归最本质的信息安全,互联网安全新媒体,4hou.com...
  18. P4379 [USACO18OPEN]Lemonade Line
  19. Jmeter压力测试图片上传
  20. 新的、老的、无所不在的毒素

热门文章

  1. xtu oj Problem B 1400 钝角三角形
  2. Simulink中构造时变传递函数的四种方法
  3. iOS 微博 sdk app私信推荐
  4. 分享一个用了很久的php日志类
  5. 命令备份文件夹,恢复文件夹
  6. 3281. CJ and WS
  7. 用 Compose 画个小老虎恭贺新春
  8. 日不落帝国下一个统领全球的领域:人工智能的伦理道德? | 附报告
  9. gstreamer教程(二)-初始化_组件(Element)_箱柜(Bins)的使用
  10. 微商引流产品有什么秘诀?为大家整理了以下几种最有效的引流方法