Chapter 5 Quiz 2 - Writing Classes
In UML diagrams, this symbol indicates that a member is public. 1.) / 2.) @ 3.) - 4.) +
+
In UML diagrams, this symbol indicates that a member is private: 1.) * 2.) # 3.) - 4.) +
-
The term "default constructor" is applied to the first constructor written by the author of a class. True False
False A default constructor is the one that does not take any parameter. It is also called as no-arg constructor.
Which of the following is not true about static methods? 1.) They are called directly from the class. 2.) It is necessary for an instance of the class to be created to execute the method. 3.) They are often used to create utility classes that perform operations on data but have no need to store and collect data. 4.) They are created by placing the key word static after the access specifier in the method header.
It is necessary for an instance of the class to be created to execute the method.
Assume the class BankAccount has been created and the following statement correctly creates an instance of the class. BankAccount account = new BankAccount(5000.00); What is true about the following statement? System.out.println(account); 1.) The account object's toString method will be implicitly called. 2.) The method will display unreadable binary data on the screen. 3.) A runtime error will occur. 4.) A compiler error will occur.
The account object's toString method will be implicitly called.
A constructor is a method that is automatically called when an object is created. True False
True
Accessors and mutators provide mechanisms for controlled access to a well-encapsulated class. True False
True Accessors provide read access to variables that otherwise would be inaccessible. Mutators provide write access to otherwise inaccessible variables.
An object should be encapsulated in order to guard its data and methods from inappropriate access. True False
True Encapsulation is the concept that objects should be protected from accidental (or purposeful) misuse.
A method defined in a class can access the class's instance data without needing to pass them as parameters or declare them as local variables. True False
True The instance data are globally available to all of the class's methods and therefore the methods do not need to receive them as parameters or declare them locally. If variables of the same name as instance data were declared locally inside a method then the instance data would be "hidden" in that method because the references would be to the local variables.
The expressions that are passed to a method in an invocation ( method call ) are called 1.) formal parameters 2.) formals 3.) formal arguments 4.) actual parameters 5.) Any of these
actual parameters The formals (formal parameters, formal arguments) are those given in a method's header, where it is declared. The actual parameters (actuals, actual arguments) are the expressions that actually are transmitted to a method in an invocation.
If a method does not have a return statement, then 1.) it cannot be called from outside the class that defined the method 2.) it must be an int, double, float, or String method 3.) it must be defined to be a public method 4.) it will produce a syntax error when compiled 5.) it must be a void method
it must be a void method All methods are implied to return something and therefore there must be a return statement. However, if the programmer wishes to write a method that does not return anything, and therefore does not need a return statement, then it must be a void method (a method whose header has void as its return type).
When a variable in a class declaration is declared static there will be ________. 1.) a copy of the field in each class object 2.) two reference copies of the field for each method in the class 3.) only one copy of the field in memory 4.) a copy of the field for each method in the class
only one copy of the field in memory
Given the following method header, what will be returned from the method?public Rectangle getRectangle() 1.) an object of the class Rectangle 2.) a graph of a rectangle 3.) the values stored in the data members of the Rectangle object 4.) the address of an object of the Rectangle class
the address of an object of the Rectangle class
If you attempt to perform an operation with a null reference variable ________. 1.) the program will terminate 2.) the resulting operation will always be zero 3.) the results will be unpredictable 4.) Java will create an object to reference the variable
the program will terminate
In a UML diagram to indicate the data type of a variable enter: 1.) the variable name followed by the data type 2.) the variable name followed by a colon and the data type 3.) the class name followed by the variable name followed by the data type 4.) the data type followed by the variable name
the variable name followed by a colon and the data type