首页 > > 详细

辅导COMP 1210辅导Practice Final Exam

COMP 1210 Practice Final Exam (M7-M11) Page 1 of 8

Last Name: ______________________ First Name: __________________________ Section: ______
Multiple Choice Select the letter in front of the most correct answer.

1. True/False: Testing and debugging are not the same activity.
a. True
b. False

2. True/False: After an array is created, its length can be increased but not decreased.
a. True
b. False

3. True/False: The protected modifier is used to indicate that a method cannot be overridden
a. True
b. False

4. True/False: A static variable is unique in that the value does not change.
a. True
b. False

5. True/False: A static method in class can never reference an instance variable of the class.
a. True
b. False

6. True/False: Having multiple methods in a class with the same name but difference signatures is
called method decompositions.
a. True
b. False

7. Suppose a method in class C1 creates an instance of class C2. A general dependency between
class C1 and class C2 is which of the following relationships?
a. C1 is-a C2
b. C2 is-a C1
c. C1 uses C2
d. C1 has-a C2
e. C2 has-a C1

8. Suppose class C2 extends class C1. An inheritance dependency is which of the following
relationships?
a. C1 is-a C2
b. C2 is-a C1
c. C1 uses C2
d. C1 has-a C2
e. C2 has-a C1

COMP 1210 Practice Final Exam (M7-M11) Page 2 of 8

9. For class C1 and class C2, suppose class C1 has an instance variable of type C2. An aggregation
dependency between class C1 and class C2 is which of the following relationships?
a. C1 is-a C2
b. C2 is-a C1
c. C1 uses C2
d. C1 has-a C2
e. C2 has-a C1

10. True/False: The parameter of the main method in Java typically contains the compiler
instructions for the program and/or the number of times to run the program.
a. True
b. False

11. True/False: A static variable can be referenced by all methods in the class.
a. True
b. False

12. In Java, interfaces may not contain _____________________. Check all that apply.
a. abstract methods
b. constants
c. public instance variables
d. private instance variables
e. private methods

13. After the line of code below is executed what will be the value of names[7]?
String[] names = new String[10];
a. 0
b. " "
c. true
d. 7
e. null


14. True/False: In Java, abstract methods always end with {}.
a. True
b. False

15. Which interface in the Java API should be used to define how objects can be compared for their
natural ordering?
a. Equality
b. Compare
c. Logical
d. Iterator
e. Comparable

COMP 1210 Practice Final Exam (M7-M11) Page 3 of 8

16. Suppose myArray is declared in the main method and then passed into method myMethod as
shown below. After myMethod completes and returns to main, what would be the result of
printing each element in the array separated by a space?

public static void main(String[] args) {
int[] myArray = new int[5];
myMethod(myArray);
for (int i : myArray) {
System.out.print(i + " ");
}
}

public static void myMethod(int[] integerArray) {
integerArray[3] += 1;
}

a. 0 0 0 0 0
b. 1 0 0 0 0
c. 0 1 0 0 0
d. 0 0 1 0 0
e. 0 0 0 1 0


17. What is printed after executing the following loop? Hint: Be aware of any method calls on null
objects.
public static void forEachPrint()
{
String[] stringArray = new String[5];
stringArray[1] = " COMP1210 ";

for (String element : stringArray)
{
System.out.print(element.trim() + " ");
}
}


a. COMP1210
b. COMP1210
c. COMP1210 null null null null
d. COMP1210 and then a NullPointerException occurs
e. NullPointerException occurs


COMP 1210 Practice Final Exam (M7-M11) Page 4 of 8

Use the code below to answer questions 18 - 21. Answer pass, fail, or neither for each JUnit test. Assume
all necessary imports.

import org.junit.Assert;
import org.junit.Test;

public class PracticeExamJUnitTest {

@Test public void firstTest() {
String s = "hello";
String s2 = "Hello";
Assert.assertTrue("Strings did not match. ", s.equals(s2));
}

@Test public void secondTest() {
double closeToZero = 0.00001;
double zero = 0;
Assert.assertEquals("Second test failed. ", zero, closeToZero, .0001);
}

@Test public void thirdTest() {
int[] listOfInts = {1, 2, 3, 4, 5};
int[] listOfOtherInts = {1, 2, 3};

boolean isPassing = listOfInts[4] % 4 == 0;
Assert.assertTrue("There was a problem in third test. ", isPassing);
}

@Test public void fourthTest() {
int[] listOfInts = {1, 2, 3, 4, 5};
Assert.assertTrue("Something went wrong. ", listOfInts[3] / 4 == 1);
}
}

18. What is the result of firstTest?
a. pass b. fail

19. What is the result of secondTest?
a. pass b. fail

20. What is the result of thirdTest?
a. pass b. fail

21. What is the result of fourthTest?
a. pass b. fail




COMP 1210 Practice Final Exam (M7-M11) Page 5 of 8

22. For the code below, you desire to print the last parameter of the variable length parameter. Fill in
the blank below to accomplish that.
public static void printTheLastParameter(int ... parameterList) {
System.out.println(__21__);
}

a. parameterList
b. parameterList[end]
c. parameterList[length]
d. parameterList[parameterList.length - 1]
e. parameterList.get(last)

23. True/False: An abstract method in a super class can never be overridden in any immediate
subclass.
a. True
b. False

24. True/False: An overridden method has the same body but different signature.
a. True
b. False

25. In Java, a parent class can have a maximum of ______ child classes?
a. 0
b. 1
c. 2
d. 3
e. None of the above.

26. True/False: The protected access modifier can be applied to the fields of a class to allow
subclasses and classes in the same package direct access to the fields.
a. True
b. False

27. Which of the following are inherited by a subclass? (circle all that apply)
a. public methods
b. public variables
c. protected variables
d. protected methods
e. constructors

28. What is the natural order of the array below?
String[] pets = {"dog", "cat, "bird", "hamster"};
a. "cat, "dog", "bird", "hamster"
b. "hamster", "dog", "cat, "bird"
c. "dog", "cat, "bird", "hamster"
d. "bird", "cat, "dog", "hamster"
e. "bird", "dog", "cat, "hamster"

COMP 1210 Practice Final Exam (M7-M11) Page 6 of 8

29. True/False: If you wanted to sort items in an order other than their natural ordering, the
Comparator interface in the Java API should be implemented.
a. True
b. False

30. Suppose s1 and s2 are objects of the String class, which implements the Comparable
interface. If the values of s1 and s2 are "sun" and "son" respectively, what is the expected
return value when s1.compareTo(s2) is called? [also: "sun".compareTo("son") ]
a. false
b. true
c. An int value greater than zero
d. An int value less than zero
e. An int value equal to zero

31. True/False: Suppose parent class P has a child class C (i.e., C extends P), and we have the
following assignment of a child C object to a reference of the parent type P:
P p = new C();
Then any method defined in the parent class P can be called on p without casting.
c. True
d. False

32. True/False: A reference variable of type C can refer to an object of class C or to an object of any
subclass of C, as well as any object the parent of C.
a. True
b. False

33. True/False: If a checked exception is not caught or listed in the throws clause and you attempt
to compile and/or execute the program, a run-time error occurs?
a. True
b. False

34. True/False: The unchecked exceptions in Java are objects of type IOException or any of its
descendants.
a. True
b. False

35. True/False: An input/output (I/O) stream is a sequence of bytes that flow from a source to a
destination.
a. True
b. False

36. Which of the following streams is typically associated with a program printing to the screen
using the println method?
a. System.err
b. System.in
c. System.out
d. b c above
e. All of the above (a, b, c)


COMP 1210 Practice Final Exam (M7-M11) Page 7 of 8

37. True/False: An Exception is an object that describes an unusual or erroneous situation.
a. True
b. False

38. True/False: If an expression that includes integer division by zero (e.g., 10 / 0) is evaluated,
an exception is thrown (i.e., run-time error occurs).
a. True
b. False

39. True/False: With respect to inheritance, a subclass inherits instance variables and instance
methods defined in its parent but not those defined in the ancestors of the parent.
a. True
b. False

40. True/False: In object-oriented programming, a class can be considered as an encapsulation of
first-generation and second-generation languages.
a. True
b. False

41. True/False: When a method is declared as private, it can be accessed within the class, but it
cannot be accessed from outside the class.
a. True
b. False

42. True/False: A public static method can be referenced from another class by using the class
name and the dot notation.
a. True
b. False

43. The signature of a method is determined by _____________________.
a. name
b. number of parameters
c. type of parameters
d. order of parameters
e. All of the above

44. Which one of the following is a correct declaration and instantiation of an array?
a. int[] scores;
b. int[] scores = new int[1.5];
c. int[] scores = {"low", "high"};
d. int[] scores = new int[15];
e. All of the above

45. True/False: When the constructor of a subclass is called, the parameterless constructor in the
super class is called only when the instance is created by a constructor with parameters.
a. True
b. False


COMP 1210 Practice Final Exam (M7-M11) Page 8 of 8


46. True/False: When a method creates a Scanner object to read from a file (i.e., a Scanner
object created with a File object as the parameter), the potential exception (e.g.,
FileNotFoundException or IOException) must be handled with try-catch blocks;
there is no other alternative.
a. True
b. false

47. True/False: When a method uses a PrintWriter object to write to a file, simply invoking the
println method on the PrintWriter object will ensure that the data is written to the file.
a. True
b. false

48. True/False: When an exception occurs the call stack trace that shows the methods that were
invoked along the path to the where the exception occurred.
a. True
b. false

49. True/False: When a method is called, if an exception occurs and it is not caught and handled in
the method, then the exception is printed immediately from the calling method rather being
propagated to the calling method.
a. True
b. false

50. True/False: When a try block is executed (and System.exit is not called), the associated
finally block (if it has one) will execute only if the try block does not throw an exception.
a. True
b. false

联系我们
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!