LECTURE FINAL
EXAM REVIEW
A class cannot inherit only the methods from its . - ANSWERS-super
classes
The goal of encapsulation is to - ANSWERS-hide the values or state of a
structured an object inside a class, preventing unauthorized direct access
to them.
Pressing a GUI button normally causes - ANSWERS-an event to occur.
In GUI coordinate system, which of the following positions refers to the
coordinates (0,0)? - ANSWERS-The top left corner of the GUI box
For the following program, trace the code and show how the final value
is derived (i.e. the values of the parameters and/or local variables in each
instance of the recursive call):
public class TestRec2{
public static void main(String []args) {
int number = 10;
PRINT( pblmOne(number));
END OF
PAGE
1
, CSE 1322 LAB AND LATEST
LECTURE FINAL
EXAM REVIEW
}
public static int pblmOne(int myNum){
if (myNum < 2)
return 3;
else
return 2 + pblmOne(myNum-2);
}
} - ANSWERS-13
For the following program, trace the code and show how the final value
is derived (i.e. the values of the parameters and/or local variables in each
instance of the recursive call):
Here, a and b are parameters for the recursive function pblm2(). Which
of the following answer choices, given below, for num1 and num2
respectively, allows this recursive function to terminate.
public class TestRec3 {
END OF
PAGE
2
, CSE 1322 LAB AND LATEST
LECTURE FINAL
EXAM REVIEW
public static void main(String []args) {
int num1;
int num2;
PRINT(pblm2(num1, num2));
}
public static int pblm2(int a, int b){
if (a == b)
return 0;
else
return pblm2(a, b + 1) + b;
}
} - ANSWERS-1, 0
A class can inherit - ANSWERS-multiple interfaces
Recursion cannot occur whenever - ANSWERS-a method calls any
other method
END OF
PAGE
3
, CSE 1322 LAB AND LATEST
LECTURE FINAL
EXAM REVIEW
A recursive method must have a - ANSWERS-a valid base case to exit,
otherwise the method execution will keep repeating.
An infinite recursion will happen as long as there is - ANSWERS-a
valid base case.
Recursion represents: - ANSWERS-a powerful programming technique
in which a method makes a call to itself from within its own method
body.
The base case (bottom of recursion) is also known as - ANSWERS-the
stopping state
If a recursive method has no base case, i.e. bottom, or if the base case is
never reached, it will - ANSWERS-become infinite and the result will
be StackOverflowException
Using recursion for a sequence such as Factorial is efficient. -
ANSWERS-non-linear
END OF
PAGE
4