IS 247 Midterm

0.0(0)
studied byStudied by 2 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/125

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

126 Terms

1
New cards

Which statement best reflects a property or characteristic of a constructor?

has the same name as the class

2
New cards

Suppose we have a String object referenced by a variable called listing. Suppose we want a new String object that consists of the first 5 characters in listing. Which of the following lines of code will achieve this?

String prefix = listing.substring(0,5);

3
New cards

Do constructors have a return type?

false

4
New cards

Static member functions can only access member variables that are also static.

True

5
New cards

A constructor is a method that __________. Choose the best answer.

performs creation, initialization or setup of an object

6
New cards

A constructor is invoked to create an object using the ________ operator.

new

7
New cards

Get methods are also called ___________ type methods.

accessor

8
New cards

How are instance member and static member variables different?

only one instance of a static variable exists in memory

9
New cards

When does a static member variable come into existence in memory?

before any instances of its class

10
New cards

Set methods are also called ___________ type methods.

mutator

11
New cards

Which method returns the number of characters stored in StringBuilder?

length()

12
New cards

Class abstraction separates class implementation from the use of the class.

true

13
New cards

When a method has the same name as another method but different parameters, it is referred to as ______________________

overloaded

14
New cards

Given the declaration Circle x = new Circle(), which of the following statement is most accurate.

x contains a reference to a Circle object

15
New cards

For the following String:

String str = "ABcdeFGH";

What will be returned from the following statements?

Character.toUpperCase(str.charAt(3));

Character.toUpperCase(str.charAt(5));

DE

16
New cards

Which of the following method headers is most likely a header for a mutator method?

public void setAge(int newAge)

17
New cards

Converting a primitive or class in Java into other type is called ______________.

casting

18
New cards

A super class can be derived from another class.

true

19
New cards

Suppose we have a String object referenced by a variable called listing. Suppose we want a new String object that consists of the first 5 characters in listing. Which of the following lines of code will achieve this?

String prefix = listing.substring(0,5);

20
New cards

Another term for an object of a class is a(n) __________.

instance

21
New cards

Which operator is used to access a data field or invoke a method from an object?

the dot operator

22
New cards

This keyword is means that a variable is not able to be modified once it is initialized.

final

23
New cards

Suppose we have a String object referenced by a variable called listing. Suppose we want a new String object that consists of the first 5 characters in listing. Which of the following lines of code will achieve this?

String prefix = listing.substring(0,5);

24
New cards

Given the declaration Circle[] x = new Circle[10], which of the following statement is most accurate?

x contains a reference to an array and each element in the array can hold a reference to a Circle object.

25
New cards

Get methods are also called ___________ type methods.

accessor

26
New cards

A method that has multiple definitions distinguished by the parameter number or type is an __________________ method.

overloaded

27
New cards

Which access specifier is most appropriate to implement encapsulation?

private

28
New cards

instances of wrapper classes are immutable.

true

29
New cards

A constructor with only one parameter is the "default" constructor.

false

30
New cards

Which method returns the number of characters stored in StringBuilder?

length()

31
New cards

A ___________ variable represents information or data shared by all objects of the class.

static

32
New cards

The "this" pointer is passed to a static member function.

false

33
New cards

Converting a primitive or class in Java into other type is called ______________.

casting

34
New cards

Suppose that Horse is a subclass of Animal, and neither class is abstract. Which of the following is an invalid declaration and initialization?

Horse h = new Animal();

35
New cards

Which class can you use to write data into a text file?

PrintWriter

36
New cards

To catch an exception, the code that might have an error must be enclosed in a ________________ block.

try

37
New cards

"try-with-resources" syntax is used to ___________________.

automatically close the files used in the program.

38
New cards

A(n) _____________________ is an object that defines an erroneous situation from which the program usually cannot recover.

error

39
New cards

A finally clause is always required in a try-catch block.

false

40
New cards

To handle an exception that has been thrown, a program must have a(n) ____________________

try/catch block

41
New cards

What does the following statement do?

Scanner scanner = new Scanner(Paths.get("test.txt"));

Opens a text file for input.

42
New cards

All exception classes inherit, either directly or indirectly, from ________.

class Throwable.

43
New cards

If the data.dat file already exists, what will happen when the following statement is executed?

FileWriter fwriter = new FileWriter("data.dat");

The file will be erased and replaced with the new file

44
New cards

Files that are open for output from a program must be explicitly closed in the program.

true

45
New cards

Which of the following exceptions is a checked exception?

IOException.

46
New cards

Which method can be used to read a whole line from the file?

nextLine

47
New cards

In a try/catch construct, after the catch statement is executed __________.

the program resumes at the statement that immediately follows the try/catch construct

48
New cards

A(n) ____________________ is used to specify how certain exceptions should be handled.

catch block

49
New cards

An uncaught exception ________.

is an exception that occurs for which there are no matching catch clauses.

50
New cards

What is the java root class for exceptions?

java.lang.Throwable

51
New cards

Which class contains the method for checking whether a file exists?

File

52
New cards

Which of the following statements regarding abstract classes and methods is FALSE?

A data field can be declared abstract.

53
New cards

Which keyword is used when requiring an interface for a class?

implements

54
New cards

Which of the following statements is correct?

An abstract class may contains constructors.

55
New cards

Which statement best reflects the definition of a Java interface?

a collection of abstract methods and constants

56
New cards

Which of the following statements regarding abstract methods is false?

A data field can be declared abstract.

57
New cards

A subclass can implement multiple interfaces.

true

58
New cards

Class abstraction separates class implementation from the use of the class.

true

59
New cards

Which of the following statements regarding abstract methods is FALSE?

An abstract class can have instances created using the constructor of the abstract class.

60
New cards

What is an abstract method?

A method which is not implemented.

61
New cards

If Person is an interface. Then it is possible to create an object by instantiating the Person interface.

false

62
New cards

Of the classes below, the one that is most likely to be declared abstract is _________________.

a) dog

b) cat

c) animal

d) horse

animal

63
New cards

Which of these access specifiers is most appropriate to use for an interface?

public

64
New cards

How many base cases must a recursive method have?

at least one

65
New cards

What is wrong with the following recursive method that computes the sum of all of the odd positive integers less than or equal to n?

public int sumOfOdds(int n)

{

if(n%2 == 0)

return sumOfOdds(n-1);

else

return n + sumOfOdds(n-2);

}

a) there are two base cases

b) adds both even and odd

c) no base case

d) recursive values don't decrement correctly

no base case

66
New cards

All mathematical problems are designed to be more efficient using recursive solutions.

false

67
New cards

Which type of recursion is more difficult to debug?

indirect

68
New cards

A problem can be solved recursively if it can be broken down into successive smaller problems that are identical to the overall problem.

true

69
New cards

Without a base case, a recursive method will call itself only once and stop.

false

70
New cards

____________________ recursion occurs when a method calls itself, while _________________ recursion when a method calls another method that then calls the original method.

a) upward, downward

b) downward, upward

c) direct, indirect

d) indirect, direct

direct, indirect

71
New cards

Recursive solutions are always more efficient than iterative solutions

false

72
New cards

In the following code that uses recursion to find the greatest common divisor of a number, what is the base case?

public static int gcd(int x, int y)

{

if (x % y == 0)

return y;

else

return gcd(y, x % y);

}

a) gcd(int x, int y)

b) if (x % y == 0)

return y;

c) else

return gcd(y, x % y);

d) cannot tell from this code

if (x % y == 0)

73
New cards

What is one of the benefits of recursion?

shorter code

74
New cards

A _____________________ method is one that calls itself.

recursive

75
New cards

25 % 5 is ______?

0

76
New cards

Which of the following is the correct statement to return JAVA?

a) String.toUpperCase("Java")

b) toUpperCase("Java")

c) "Java".toUpperCase()

d) "Java".toUpperCase("Java")

"Java".toUpperCase()

77
New cards

What is the index variable for the element at the second row and first column in array a?

a) a[0][1]

b) a[2][1]

c) a[1][0]

d) a[1][1]

a[1][0]

78
New cards

What is the exact output of the following code?

public class MyClass {

public static void main(String args[]) {

float num = 7.3f;

System.out.print("num");

System.out.print(num);

}

}

a) 7.3

b) num7.3f

c) num7.3

d) 7.37.3

num7.3

79
New cards

What is displayed in the following code?

public class Test {

public static void main(String[] args) {

int x = 1;

int y = x-- + x;

System.out.println("y is " + y);

}

}

a) y is 1

b) y is 4

c) y is 2

d) y is 3

y is 1

80
New cards

When you invoke a method with a parameter, the value of the argument is passed to the parameter. This is referred to as _________.

pass by value

81
New cards

Suppose x is 1. What is x after x += 1?

2

82
New cards

The __________ method returns a raised to the power of b.

a) Math.pow(b, a)

b) Math.pow(a, b)

c) Math.power(a, b)

d) Math.exponent(a, b)

Math.pow(a, b)

83
New cards

How many times will the following code print "Welcome to Java"?

int count = 0;

while (count

11

84
New cards

"abc".compareTo("aba") returns ___________.

a) -1

b) 2

c) -1

d) 1

2

85
New cards

How many elements are array matrix (int[][] matrix = new int[2][5])?

a) 20

b) 10

c) 25

d) 14

10

86
New cards

Which loop statement will execute the code before the loop condition is tested?

a) for each

b) for

c) while

d) do-while

do-while

87
New cards

An _____ object cannot be modified

immutable

88
New cards

the _____ clause is always executed regardless of wether an exception occurred or not

finally

89
New cards

the keyword _____ can be used to refer to its calling object. It can also be used inside a constructor ti invoke another constructor of the same class

this

90
New cards

_____ is a special form of association between classes that represents an ownership between objects

aggregation

91
New cards

the separation of class implementation from the use of a class is called class ______

abstraction

92
New cards

_____ means that a variable of a supertype can refer to a subtype object

polymorphism

93
New cards

a _____ is a template for objects

class

94
New cards

the keyword _____ can be used to invoke the superclass's methods and constructors

super

95
New cards

_____ means to define multiple methods with the same name but different signatures

overloading

96
New cards

_____ means ti provide a new implementation for a method in the subclass

overriding

97
New cards

_____ enables a program to deal with exceptional situations in an orderly manner

exception handling

98
New cards

using _____ you can define a general class and extend it into a more specialized class

inheritance

99
New cards

when an object reference can be typecast into another object reference it is called _____

casting

100
New cards

Converting a primitive value to a wrapper object is called _____.

boxing