1 | Page
cse 2221 midterm 2 Questions and Correct
Answers
what is the definition of the size of a tree? Ans: # of nodes in a
tree
what is the definition of the height of a tree? Ans: longest path
from root to leaf in a tree (largest # of nodes)
what is the definition of a path? what is the length of a path? Ans:
a series of nodes connected by edges where each node is a parent
or child of another
length is the # in a path
what is the value range of a NaturalNumber? Ans: [0, ∞)
technically limited by memory though
what is the benefit of using the String constructor over the int
constructor? Ans: int has a limit while Sytring has a much, much
longer limit
what types of methods are in the NaturalNumber interface(s)? Ans:
instance methods
© 2025 All rights reserved
, 2 | Page
if I write "nn.isZero();" what is "nn" called? Ans: receiver
what does "@ensures this = #this + 1" mean in a method contract?
Ans: new value of this will be equal to the old value of this plus
one
if I write "nn.increment()", does anything change about "nn"? what
changes? Ans: yes, object value changes
when should you use copyFrom over transferFrom? Ans: if you
have x.copyFrom(y), this says you will still need y at its current
value later in the code
if n1 > n2, what is the result of "n1.compareTo(n2)"? Ans: any
value x where x > 0 (i.e. a positive number)
in the function call "nn.multiplyBy10(k)", what is "k" for? Ans:
adding to ones place after multiplying
what are the kernel methods? Ans: isZero, multiplyBy10,
divideBy10
very essential methods to be used in all NaturalNumber objects
what is the default value of a NaturalNumber? Ans: 0
what is the resulting object value of the argument passes to a
transferFrom call? Ans: 0
© 2025 All rights reserved
, 3 | Page
what are reference types associated with? Ans: objects
is String a primitive or reference type? Ans: reference
is the value of a primitive type the actual value or is it a memory
address? Ans: actual
is the value of a reference type the actual value or is it a memory
address? Ans: memory
how many values does a reference type have? what are they? Ans:
2 - reference value and object value
draw the representation for the line "String myStr = "No class until
March 30th lol";" Ans: my Str triangle arrow to "No class until
March 30th lol" circled
draw the representation for the line "naturalNumber myNN = new
NaturalNumber2(400 + 55);"
what is the object value of the line of code? Ans: MyNN triangle
arrow to 455 in rectangle
455
© 2025 All rights reserved
cse 2221 midterm 2 Questions and Correct
Answers
what is the definition of the size of a tree? Ans: # of nodes in a
tree
what is the definition of the height of a tree? Ans: longest path
from root to leaf in a tree (largest # of nodes)
what is the definition of a path? what is the length of a path? Ans:
a series of nodes connected by edges where each node is a parent
or child of another
length is the # in a path
what is the value range of a NaturalNumber? Ans: [0, ∞)
technically limited by memory though
what is the benefit of using the String constructor over the int
constructor? Ans: int has a limit while Sytring has a much, much
longer limit
what types of methods are in the NaturalNumber interface(s)? Ans:
instance methods
© 2025 All rights reserved
, 2 | Page
if I write "nn.isZero();" what is "nn" called? Ans: receiver
what does "@ensures this = #this + 1" mean in a method contract?
Ans: new value of this will be equal to the old value of this plus
one
if I write "nn.increment()", does anything change about "nn"? what
changes? Ans: yes, object value changes
when should you use copyFrom over transferFrom? Ans: if you
have x.copyFrom(y), this says you will still need y at its current
value later in the code
if n1 > n2, what is the result of "n1.compareTo(n2)"? Ans: any
value x where x > 0 (i.e. a positive number)
in the function call "nn.multiplyBy10(k)", what is "k" for? Ans:
adding to ones place after multiplying
what are the kernel methods? Ans: isZero, multiplyBy10,
divideBy10
very essential methods to be used in all NaturalNumber objects
what is the default value of a NaturalNumber? Ans: 0
what is the resulting object value of the argument passes to a
transferFrom call? Ans: 0
© 2025 All rights reserved
, 3 | Page
what are reference types associated with? Ans: objects
is String a primitive or reference type? Ans: reference
is the value of a primitive type the actual value or is it a memory
address? Ans: actual
is the value of a reference type the actual value or is it a memory
address? Ans: memory
how many values does a reference type have? what are they? Ans:
2 - reference value and object value
draw the representation for the line "String myStr = "No class until
March 30th lol";" Ans: my Str triangle arrow to "No class until
March 30th lol" circled
draw the representation for the line "naturalNumber myNN = new
NaturalNumber2(400 + 55);"
what is the object value of the line of code? Ans: MyNN triangle
arrow to 455 in rectangle
455
© 2025 All rights reserved