Title | CS1102 AY2021 Final Exam (Day1-4) Review Quiz |
---|---|
Course | Programming 1 |
Institution | University of the People |
Pages | 69 |
File Size | 862.5 KB |
File Type | |
Total Downloads | 700 |
Total Views | 876 |
CS 1102 - AY2021 Final Exam (Days 1 - 4) Review QuizQuestion 1Which of the following can a class NOT be used for? Select one: a. a container for static methods (subroutines) b. a container for static variables c. a primitive type d. a type for method parameters e. a type for variablesYour answer is ...
CS 1102 - AY2021 Final Exam (Days 1 - 4) Review Quiz
Question 1
Which of the following can a class NOT be used for?
Select one:
a. a container for static methods (subroutines)
b. a container for static variables
c. a primitive type
d. a type for method parameters
e. a type for variables
Your answer is correct.
Primitive types are not classes. See Section 2.3 of Eck (2014).
The correct answer is: a primitive type
Question 2
Consider the following first line from a Java method definition.
public static boolean compute(int n, float x) {
Which one of the following lines could begin a method that legally overloads the above method?
Select one:
a. private static boolean compute(int n, float x) {
b. public boolean compute(int n, float x) {
c. public static int compute(int n, float x) {
d. public static boolean compute(float n, int x) {
e. public static boolean compute(int x, float n) {
Your answer is correct.
To overload a method, a method must have the same name but different parameter types (or a different number of parameters). See Section 4.3.3 of Eck (2014).
The correct answer is: public static boolean compute(float n, int x) {
Question 3
What is the output of the following Java program?
import java.util.*;
class ArrayGames {
public static void main(String[] args) {
ArrayList a = new ArrayList();
for (int i = 1; i...