錯題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