OSU CSE 2221 Final Review Exam Questions AND Correct
Answers
A type is an immutable type if:
*a.* it is illegal to copy a reference of that type, so there can be no
aliasing
*b.* for every instance method of that type, this and every other
parameter of that type is a restores-mode parameter
*c.* that type has a no-argument constructor
*d.* a function method may not return a result of that type - ✔✔b
After execution of the following code, what are the declared type
(static type) and the object type (dynamic type) of nCopy?
NaturalNumber n = new NaturalNumber2( );
NaturalNumber nCopy = new NaturalNumber1L(n);
*a.* declared type is NaturalNumber, object type is NaturalNumber1L
*b.* declared type is NaturalNumber, object type is NaturalNumber2
*c.* declared type is NaturalNumber2, object type is
NaturalNumber1L
*d.* declared type is NaturalNumber1L, object type is
NaturalNumber2 - ✔✔a
,After the two variables are declared and initialized, which java
instruction will set the value of b to true?
NaturalNumber n = new NaturalNumber2( );
NaturalNumber k = new NaturalNumber2(1);
*a.* boolean b = k.compareTo(n) == 1;
*b.* boolean b = n.compareTo(k) < 0;
*c.* boolean b = n <= k;
*d.* boolean b = n.!equals(k); - ✔✔b
An XMLTree created from an RSS 2.0 feed will have which of these
properties?
*a.* the root is a node with the <channel> tag
*b.* child 0 of the <channel> tag node must be a <title> tag node
*c.* no particular order is required among the children of an <item>
tag node
*d.* at least one child of the <item> tag node must be a <title> tag
node
*e.* none of the above - ✔✔c
,API stands for:
*a.* Advanced Programming Index
*b.* Advanced Power Interface
*c.* Access Port Input
*d.* Application Personal Interface
*e.* Application Programming Interface - ✔✔e
Assume n is an int variable. Which Java expression is true exactly
when n is an odd number, i.e., not divisible by 2, and should be used
to check for this situation? (hint: don't forget negative numbers!)
*a.* n % 2 == 1
*b.* n % 2 != 1
*c.* n % 2 == 0
*d.* n % 2 != 0
*e.* none of the above - ✔✔d
Consider the following array declaration and initialization. What is the
value of the expression (a[1] + a[3])?
String [ ] a = {"A", "B", "C", "D" };
, *a.* "AC"
*b.* "BD"
*c.* "ABC"
*d.* "CD" - ✔✔b
Consider the following code fragment:
int x = 8;
while ((x / 3) != 2) { x = x - 1; }
How many times will the body of the loop execute?
*a.* 0
*b.* 1
*c.* 2
*d.* 3
*e.* the loop will never terminate - ✔✔a
Consider the following code:
private static int examScore(int studentNumber) { ... }
int k = examScore(42);
Answers
A type is an immutable type if:
*a.* it is illegal to copy a reference of that type, so there can be no
aliasing
*b.* for every instance method of that type, this and every other
parameter of that type is a restores-mode parameter
*c.* that type has a no-argument constructor
*d.* a function method may not return a result of that type - ✔✔b
After execution of the following code, what are the declared type
(static type) and the object type (dynamic type) of nCopy?
NaturalNumber n = new NaturalNumber2( );
NaturalNumber nCopy = new NaturalNumber1L(n);
*a.* declared type is NaturalNumber, object type is NaturalNumber1L
*b.* declared type is NaturalNumber, object type is NaturalNumber2
*c.* declared type is NaturalNumber2, object type is
NaturalNumber1L
*d.* declared type is NaturalNumber1L, object type is
NaturalNumber2 - ✔✔a
,After the two variables are declared and initialized, which java
instruction will set the value of b to true?
NaturalNumber n = new NaturalNumber2( );
NaturalNumber k = new NaturalNumber2(1);
*a.* boolean b = k.compareTo(n) == 1;
*b.* boolean b = n.compareTo(k) < 0;
*c.* boolean b = n <= k;
*d.* boolean b = n.!equals(k); - ✔✔b
An XMLTree created from an RSS 2.0 feed will have which of these
properties?
*a.* the root is a node with the <channel> tag
*b.* child 0 of the <channel> tag node must be a <title> tag node
*c.* no particular order is required among the children of an <item>
tag node
*d.* at least one child of the <item> tag node must be a <title> tag
node
*e.* none of the above - ✔✔c
,API stands for:
*a.* Advanced Programming Index
*b.* Advanced Power Interface
*c.* Access Port Input
*d.* Application Personal Interface
*e.* Application Programming Interface - ✔✔e
Assume n is an int variable. Which Java expression is true exactly
when n is an odd number, i.e., not divisible by 2, and should be used
to check for this situation? (hint: don't forget negative numbers!)
*a.* n % 2 == 1
*b.* n % 2 != 1
*c.* n % 2 == 0
*d.* n % 2 != 0
*e.* none of the above - ✔✔d
Consider the following array declaration and initialization. What is the
value of the expression (a[1] + a[3])?
String [ ] a = {"A", "B", "C", "D" };
, *a.* "AC"
*b.* "BD"
*c.* "ABC"
*d.* "CD" - ✔✔b
Consider the following code fragment:
int x = 8;
while ((x / 3) != 2) { x = x - 1; }
How many times will the body of the loop execute?
*a.* 0
*b.* 1
*c.* 2
*d.* 3
*e.* the loop will never terminate - ✔✔a
Consider the following code:
private static int examScore(int studentNumber) { ... }
int k = examScore(42);