CSCI1301 Exam 2 Questions And Correct Answers
True or false: A while loop may execute the body of the loop *zero times* (perform zero
iterations) - ANSWER True
A while loop keeps repeating the body of the loop until. - ANSWER The controlling
Boolean expression becomes false
What happens if a loop never reaches a stopping point and becomes an infinite loop? -
ANSWER You have to abort the program manually
A for-loop has three parts: an initializing action, a Boolean expression, and an update
action. Which one of the following three occurs for the first time *after* the first iteration
of the loop? - ANSWER Update Action
True or false: There are some circumstances where it is impossible to use a while loop.
In such circumstances, you must use a for loop. - ANSWER False
True or False It is generally better to use a do-while loop than a while loop if you are
certain that the body of the loop should execute at least *once*. - ANSWER True
What is the key reason you would want to use a do-while loop instead of a while loop? -
ANSWER If you want the body of the loop to at least run once
What does the *continue* statement do? - ANSWER Skips the current iteration of a loop
body
True or False A single array can contain values of *different* data types. - ANSWER
False
, True or False An array must contain at least *2* elements. - ANSWER False
True or False You could have a program that has 2 arrays. One array stores int values
and the other stores String values. - ANSWER True
Which index is associated with the first element in an array? ANSWER 0
Is an array an object or a primitive data type? ANSWER Object
How would you find the size of the array? ANSWER Use arrayName.length
How does an object differ from a class? - ANSWER A class is a general definition for
objects. Objects are particular instances of the class which have values for the instance
variables.
What are the two main things that a class specifies for objects? - ANSWER Attributes
and actions(behaviours)
What type of method is the *main* method? - ANSWER Void
True or False Methods can have variables declared inside of them. - ANSWER True
True or False All methods must return a value or an object. - ANSWER False
If I had an object named fido and a method named bark, how would you call the method
bark on the fido object? - ANSWER fido.bark();
True or false: A variable that is declared *outside* of any method is called a *local*
variable. - ANSWER False
True or false: A while loop may execute the body of the loop *zero times* (perform zero
iterations) - ANSWER True
A while loop keeps repeating the body of the loop until. - ANSWER The controlling
Boolean expression becomes false
What happens if a loop never reaches a stopping point and becomes an infinite loop? -
ANSWER You have to abort the program manually
A for-loop has three parts: an initializing action, a Boolean expression, and an update
action. Which one of the following three occurs for the first time *after* the first iteration
of the loop? - ANSWER Update Action
True or false: There are some circumstances where it is impossible to use a while loop.
In such circumstances, you must use a for loop. - ANSWER False
True or False It is generally better to use a do-while loop than a while loop if you are
certain that the body of the loop should execute at least *once*. - ANSWER True
What is the key reason you would want to use a do-while loop instead of a while loop? -
ANSWER If you want the body of the loop to at least run once
What does the *continue* statement do? - ANSWER Skips the current iteration of a loop
body
True or False A single array can contain values of *different* data types. - ANSWER
False
, True or False An array must contain at least *2* elements. - ANSWER False
True or False You could have a program that has 2 arrays. One array stores int values
and the other stores String values. - ANSWER True
Which index is associated with the first element in an array? ANSWER 0
Is an array an object or a primitive data type? ANSWER Object
How would you find the size of the array? ANSWER Use arrayName.length
How does an object differ from a class? - ANSWER A class is a general definition for
objects. Objects are particular instances of the class which have values for the instance
variables.
What are the two main things that a class specifies for objects? - ANSWER Attributes
and actions(behaviours)
What type of method is the *main* method? - ANSWER Void
True or False Methods can have variables declared inside of them. - ANSWER True
True or False All methods must return a value or an object. - ANSWER False
If I had an object named fido and a method named bark, how would you call the method
bark on the fido object? - ANSWER fido.bark();
True or false: A variable that is declared *outside* of any method is called a *local*
variable. - ANSWER False