CS 1400 MIDTERM QUESTIONS WITH VERIFIED
ANSWERS
True or false: You cannot call a method from within another method - Answers - F
True or false: If you want your program to execute code for either a TRUE or FALSE
condition in a branch you MUST use an If-else statement - Answers - T
What is stack memory - Answers - The region where a method's local variables are
allocated during a method call
Which of the following are good practices for fixing errors: - Answers - 1. Focus on the
first error message, ignore the rest
2. Look at the reported line of the first error message. If error found fix. Else, look at the
previous few lines of code.
3. Compile, repeat
Which of the following are types of software testing: - Answers - 1. Regression Testing
2. Unit Testing
Which code segment does NOT contain an error
Segment 1
21 = numPeople;
Segment 2
int amountDue = -55;
Segment 3
int numDays;
int numYears;
, numDays = numYears * 365;
Segment 4
int numCars = 0;
int numPeople = 21;
numPeople + 21 = numCars -1; - Answers - Segment 2
Which code snippet below is the is the best way to compare to strings:
Assume the following
String testWord;
testWord = "Test"; - Answers - testWord.equals("Test");
What is a testbench - Answers - A program whose job is to thoroughly test another
program via a series of input/output checks
What is a block of code when scoping variables - Answers - a brace-enclosed {...}
sequence of statements that determines variable scope
Given the following code snipped:
int numPeople;
numPeople = 5;
numPeople = 10;
What is the value of numPeople after all the statements execute - Answers - 10
True or false: Using assertions is a preferred way to test a method - Answers - T
ANSWERS
True or false: You cannot call a method from within another method - Answers - F
True or false: If you want your program to execute code for either a TRUE or FALSE
condition in a branch you MUST use an If-else statement - Answers - T
What is stack memory - Answers - The region where a method's local variables are
allocated during a method call
Which of the following are good practices for fixing errors: - Answers - 1. Focus on the
first error message, ignore the rest
2. Look at the reported line of the first error message. If error found fix. Else, look at the
previous few lines of code.
3. Compile, repeat
Which of the following are types of software testing: - Answers - 1. Regression Testing
2. Unit Testing
Which code segment does NOT contain an error
Segment 1
21 = numPeople;
Segment 2
int amountDue = -55;
Segment 3
int numDays;
int numYears;
, numDays = numYears * 365;
Segment 4
int numCars = 0;
int numPeople = 21;
numPeople + 21 = numCars -1; - Answers - Segment 2
Which code snippet below is the is the best way to compare to strings:
Assume the following
String testWord;
testWord = "Test"; - Answers - testWord.equals("Test");
What is a testbench - Answers - A program whose job is to thoroughly test another
program via a series of input/output checks
What is a block of code when scoping variables - Answers - a brace-enclosed {...}
sequence of statements that determines variable scope
Given the following code snipped:
int numPeople;
numPeople = 5;
numPeople = 10;
What is the value of numPeople after all the statements execute - Answers - 10
True or false: Using assertions is a preferred way to test a method - Answers - T