Hello, dear friend, you can consult us at any time if you have any questions, add WeChat: daixieit

SAMPLE FINAL EXAM PRACTICE FOR 2020 SPRING CMPINF 401

#1)       I want to run a program Q1.java to print the sum of the numbers entered on the command line: –

like below

C:\> java Q1 12 34 32 54 56 76 89

Here’s the code for Q1.java.  Select an answer below that describes the outcome.

 

A            Won’t even compile. Will produce compilation errors from the javac command.  **

B           sumOfArgs value printed at end will be wrong

C           sumOfArgs value printed at end will be correct

D           Crashes because it does not first verify that the user entered a sufficient number of args

#2)        If I execute a program Q2.java at the command line like this:

C:\> java Q2

What will be true about the args array at the moment the program starts to execute?

A            it will be null

B            it will not be null but will be of length 0

C

D

E

It will be of length 1 it will be of length 2 it will be of length 3

containing:  [“C:\> java Q2”]

containing:  [“java”][“Q2”]

containing:  [“C:\>”][“java”][“Q2”]

#3)        Here is a java file that compiles cleanly with no errors:

 

What will happen if I execute it from the command line like this:

C:\> java Q3

A            it will execute but produce no output since there are no point statements

B            it will not execute  ** HAS NO MAIN METHOD SO IT CANT RUN

C

D

it will start to execute but immediately give a fatal error

it will execute but then hang up in an infinite loop until you hit ^C

#4)        In java, which of the following statements is true:

A            Every executable program is a class

B

C

Every class is an executable program

Every class has a main method

#5)       What is the output of the following program?

 

A            0 2 4 6 8

B            0 0 0 0 0

C            null pointer exception

D            index out of bounds exception

E            none of the above

#6)      Which of the following statements is true about Q5 above?

A            line 9 is making a copy of all 5 ints in the array and handing off that chunk of ints to fillArr

B            line 9 is just handing off a copy of arr’s reference to the fillArr method

C

D

the fillArr() call on line 9 returns and replaces itself with a reference to arr

none of the above

#7)      What is the output of the following program?

 

A            0 2 4 6 8

B            0 0 0 0 0

C            null pointer exception

D            index out of bounds exception

E            none of the above

#8)       Which of the following statement s is true about Q7 above?

A           the copyArr() method is copying all 5 ints from the src array to the copy array  (DEEP COPY)

B            the copyArr() method  is just returning the reference value in  arr1  (SHALLOW COPY)

C            none of the above

#9)        Recall the Fraction class you wrote. Suppose that you were to remove the setNumer() and

setDenom() methods from your class definition.  What would then be true about your modified Fraction class?

A            it would be an immutable class  (like String)

B

C

D

it would be a final class

it would be an abstract class

it would be an interface

#10)    Recall the Swamp program. Which of the following statements are true?

A           You can solve it without recursion easily with just a nested loop if there is only 1 path out and no

cycles or dead ends

B            Every call to DFS pushes a copy of the DFS method onto the top of the call stack

C            If you try to solve a complex multi path multi cycle dead end swamp you cannot do it without

recursion or having to write your own version of a call stack.

D           Al of the above are true

#11)     Recall the Jumbles program you wrote twice (once as a project then as a lab). Which of the following statements is true about that program?

A            matching a jumbles word to a dictionary word by generating all the permutations of the jumbles

word is very fast but requires a vast amount of storage.

B            matching a jumbles word to a dictionary word by generating all the permutations of the jumbles

requires a very little storage but requires a small eternity of time on big strings

C

D

Both A & B are true

None of the above are true

#12)     Which of the following are necessary components of a recursive solution?

A          a base case

B           a reduction of the input or search space toward the base case

C           a recursive call

D          all of the above

E           none of the above