错题2:In order to preserve encapsulation of an object, we would do all of the following except for which one?
A . Make the instance data private
B . Define the methods in the class to access and manipulate the instance data
C . Make the methods of the class public
D . Make the class final
E . All of the above preserve encapsulation
缘由及理解状况:final与分装无关。
错题3:If a method does not have a return statement, then
A . it will produce a syntax error when compiled
B . it must be a void method
C . it can not be called from outside the class that defined the method
D . it must be defined to be a public method
E . it must be an int, double, float or String method
缘由及理解状况:没有返回值时必定要用void。
错题4:Consider a Rational class designed to represent rational numbers as a pair of int's, along with methods reduce (to reduce the rational to simplest form), gcd (to find the greatest common divisor of two int's), as well as methods for addition, subtraction, multiplication, and division. Why should the reduce and gcd methods be declared to be private.
A . Because they will never be used
B . Because they will only be called from methods inside of Rational
C . Because they will only be called from the constructor of Rational
D . Because they do not use any of Rational's instance data
E . Because it is a typo and they should be declared as public
缘由及理解状况:声明为私有的类的全部项只能由该类中的实体访问,不管它们是实例数据仍是方法。
错题5:What happens if you declare a class constructor to have a void return type?
A . You'll likely receive a syntax error
B . The program will compile with a warning, but you'll get a runtime error
C . There's nothing wrong with declaring a constructor to be void
D . The class' default constructor will be used instead of the one you're declaring