Programming in Java Multiple Choice Questions 1) Methods can be added to objects a) to move objects b) to define behavior c) to rotate objects d) to turn objects Answer: b 2) move and turn are examples of a) built-in methods b) custom methods c) functions to manipulate objects d) all of the above Answer: a 3) A variable is a a) name that represents a value b) reference to the memory location that holds a value c) both a) and b) d) none of the above Answer: c 4) Variable declaration defines a) only the name of the variable b) an address in the memory c) the type of data the variable can hold d) both a) and c) Answer: d 5) Numeric data types include: a) integers only b) characters and strings c) integers and floating point type d) only floating point type Answer: c 6) A variable of a Boolean data type can hold a) any numeric values b) characters c) a true or false value d) all of the above Answer: c 7) A variable declared in a method is called a) global data b) local data c) formal data d) actual data Answer: b 8) A mathematical expression is a combination of a) operands and operators b) values c) variables d) parameters Answer: a 9) Expression allows you to a) change the object’s behavior b) speed up the programming process c) calculate new values dynamically from current values d) a) and c) Answer: d 10) The purpose of the function random number is a) only to get a random number between 0 and 1 b) to make an object behave differently c) to stop the animation at a random time d) all of the above Answer: b 11) The function random number accepts parameters that a) define a maximum generated number’s value b) specify how many numbers need to be generated c) specify the range of the random number generated d) define a minimum generated number’s value Answer: c 12) A Boolean parameter in the random number function specifies a) how many numbers need to be generated b) what is the data type of a generated number c) how generated numbers will be used d) the range of numbers generated Answer: b 13) A method’s parameter can be a) only of the numeric data type b) any data type except object c) any data type including object d) only character data type Answer: c 14) The number of parameters that the method can contain is a) only one b) usually two or three c) not more than three d) as many as needed Answer: d 15) The parameters of a method a) cannot be changed within the method b) cannot be a constant c) makes the method useful in many situations d) all of the above Answer: c True or False Questions 1) The most efficient approach to building a program is to develop one method that controls the entire animation. Answer: False 2) Methods can be developed to define additional behavior for objects. Answer: True 3) Code can be better organized if the programmer defines an appropriate set of methods. Answer: True 4) A variable is a value that changes. Answer: False 5) A variable can be used anywhere in the program, even before the declaration. Answer: False 6) A variable declared in a method can only be used in that method. Answer: True 7) Expressions can be used for calculations and use the current values of variables. Answer: True 8) The random number generation program can only produce numbers within the range 0 to 1. Answer: False 9) Only one or two parameters can be accepted by a method. Answer: False 10) Parameters can have only numeric values. Answer: False Short Answer Questions 1) _______ define behaviors for objects. Answer: Methods 2) Multiple methods allow you to better control the entire _______. Answer: animation 3) Methods can consist of several _____ to other methods. Answer: calls 4) Each variable must have a _____ that is a reference to its memory location. Answer: name 5) ________ and ______ _____ are two types of numeric data that a variable can hold. Answer: integer, floating point 6) Object properties are managed using ________. Answer: variables 7) Variables declared within the method are called _____ variables. Answer: local 8) All variables used in the method must be ________. Answer: declared 9) An expression is a combination of ________ and _________. Answer: operators, operands 10) Current values of variables can be used in a __________ _________ to calculate the value of another variable Answer: mathematical expression 11) Methods used for object manipulation are either _______ or _________. Answer: built-in, custom 12) The random number function generates numbers within the ____ , and it is controlled by some parameters accepted by that function. Answer: range 13) To make an object behave differently over time, the programmer needs to make some parameter _______. Answer: random 14) Writing methods based on the parameters’ values passed to them makes them more _____. Answer: useful 15) For every parameter added to a method, _____ and _____ need to be specified. Answer: name, type