1. What does the following code print?
2. The following code will print 16.
3. Given the following code, what is the value of b when it finishes executing?
4. What is the value of s1 after the following code executes?
5. The value of pos after the following code executes is 5.
6. What is printed when the following code executes and x has been set to zero and y is set to 3?
7. If the score is less than 60, the value of grade would be 'E'.
8. Assume that SomeClass and MainClass are properly defined in separate files. What is the output of main()?
9. The following code will print 'second'.
10. What are the values of var1 and var2 after the following code segment is executed and the while loop finishes?
11. Analyse the code and the desired output. The code snippet would correctly produce the desired output.
12. Which of the following best explains why the code will not compile?
13. What are the values in a after mult(2) executes?
private int[ ] a = {1, 3, -5, -2};
public void mult(int amt)
{
int i = 0;
while (i < a.length)
{
a[i] = a[i] * amt;
} // end while
} // end method
Due to an infinite loop, this code does not stop running!
{1, 3, -5, -2}
{3, 9, -15, -6}
{2, 6, -10, -4}
14. The values in a after multAll(3) executes are: {3, 9, -15, -6}
15. When the following code executes, ["Selasie", "Lillith", "Sharon"] will be printed.
16. What will print when this code is run?
17. In the following array, the value 6 is at row 0 and column 2.
18. Which of the following statements assigns the letter S to the third row and first column of a two-dimensional array named strGrid (assuming row-major order).
19. Read the following excerpt and select the correct answer.
A vintage store wishes to go online.
Customers can search for and order via a website.
The store has books, films and old records.
For each type of published material
(books, films, records) they need to track the
id, title, author(s), date published, and price.
Which of the following would you suggest as the
best, most efficient, design?
Create classes Book, Film, and Record with the requested fields.
Create classes for each
Create the class Vintage Material with children classes of Book, Film, and Record.
Create one class Vintage Material with the requested fields plus type.
20. Read the following excerpt and select the correct answer.
21. How many columns does a have if it is created as follows?
22. Read the following excerpt and select the correct answer.
A realtor (real estate) house selling company
needs a program to store information
about their latest houses for sale.
For each house, they want to store and
track the following information:
>number of bedrooms (<2 or 4+),
>whether the house has a garden
>and its average gas and electricity bills per month.
Which of the following is the best design?
Use a class House with three subclasses: Bedrooms,Garden, and AvgBills.
Use classes: Bedrooms,Garden, AvgBills, each with a subclass House.
Use four unrelated classes: House, Bedrooms, Garden, and AverageBills.
Use a class House, with fields: numbedrooms, hasGarden, and avgbills.
23. How many recursive calls does the following method contain?
24. In the following code, line 7 has two recursive calls.
25. Which line has the recursive call in the following code?