click below
click below
Normal Size Small Size show me how
Java (Chapter 9)
Classes/Objects
Question | Answer |
---|---|
9.1 ____________ represents an entity in the real world that can be distinctly identified. | An object |
9.2 _____________ is a construct that defines objects of the same type. | A class |
9.3 An object is an instance of a _________ . | class |
9.4 The keyword ________ is required to declare a class. | class |
9.5 ___________ is invoked to create an object. | A constructor |
9.6 [True or False] A default constructor is provided automatically if no constructors are explicitly declared in the class. | True |
9.6 [T/F] At least one constructor must always be defined explicitly. | False |
9.6 [T/F] Every class has a default constructor. | False |
9.6 The default constructor is a no-arg constructor. | True |
9.7 [T/F] Multiple constructors can be defined in a class. | True |
9.7 [T/F] Constructors do not have a return type, not even void. | True |
9.7 [T/F] Constructors must have the same name as the class itself. | True |
9.7 [T/F] Constructors are invoked using the “new” operator when an object is created. | True |
9.12 The default value for data field of a “boolean” type, “numeric” type, “object” type is _______, respectively. | false, 0, null |
9.13 [T/F] Local variables do not have default values. | True |
9.13 [T/F] Data fields have default values. | True |
9.13 [T/F] A variable of a primitive type holds a value of the primitive type. | True |
9.13 [T/F] A variable of a reference type holds a reference to where an object is stored in the memory. | True |
9.13 [T/F] You may assign an int value to a reference variable. | False |
9.10 Explain the given the declaration of “Circle x = new Circle()”. | “x” is the reference variable that can reference a “Circle” object or null if it does not reference any object. |
9.17 [T/F] A reference variable is an object. | False because a reference variable is not an object, it is a reference that points to an object. |
9.17 [T/F] A reference variable references to an object. | True |
9.17 [T/F] A data field is a class must be a primitive type. | False because a class may have a data field of an object type such as a String. |
9.17 [T/F] A data field in a class can be of an object type. | True |
9.19 [T/F] When creating a Random object, you have to specify the seed or use of the default seed. A “seed” is a number used to initialize a random number generator. | True |
9.19 [T/F] If two Random objects have the same seed, the sequence of the random numbers obtained from these two objects are identical. | True |
9.19 [T/F] The “nextInt()” method in the Random class returns the next random int value. | True |
9.19 [T/F] The “nextDouble()” method in the Random class returns the next random double value. | True |
9.20 To obtain the distance between the points (40,50) and (5.5, 4.4), use ___________ . | “new Point2D(40,50).distance(5.5,4.4)” or “new Point2D(40,50).distance(new Point2D(5.5,4.4))” “new Point2D(5.5,4.4).distance(40,50)” or “new Point2D(5.5,4.4).distance(new Point2D(40,50))” |
9.21 Variables that are shared by every instance of a class are ______________ . | class variables |
9.23 A method that is associated with an individual object is called ____________ . | an instance method |
9.24 To declare a constant MAX_LENGTH as a member of the class, you write ____________ . | “final static double MAX_LENGTH = 99.98” [A “constant” is known as a final variable and represents permanent data that never changes. The word “final” is a Java keyword for declaring a constant. Format: final data type CONSTANTNAME = value;] |
9.29 Suppose the xMethod() is invoked in the following constructor in a class, xMethod() is ______ in the class. [public MyClass() { xMethod(); } ] | A static method or an instance method. |
9.30 Suppose the xMethod() is invoked from a main method in a class, xMethod() is ______ in the class. [public static void main(String[] args) { xMethod(); } ] | a static method |
9.31 To prevent a class from being instantiated, ____________ . | use the private modifier on the constructor |