Java Programming Midterm Exam
Java Programming Midterm Exam
Java Programming Midterm Exam
int x=5;
if (x>6)
System. out. println("x>l");
else if (x>=5)
System. out .println("x>=5");
else if (x<10)
System. out. println("x<10");
else
System.out.println("none of the above");
____________________
x>=5
12. What symbol(s) is used to separate multiple exceptions in one catch statement?
_____________________________
A single vertical bar |
15. The main purpose of unit testing is to verify that an individual unit (a class,
in Java) is working correctly before it is combined with other components in the
system. True or false?
_______________________________
true
16. Unit testing is the phase in software testing in which individual software
modules are combined and tested as a whole. True or false?
_______________________________
false
17. Virtual method invocation must be defined with the instanceof operator.
True or false?
______________________________
false
18. You can always upcast a subclass to an interface provided you don't need to
access any members of the concrete class.
True or false?
___________________________
true
20. You can't downcast an object explicitly because you must use virtual method
invocation.
True or false?
________________________
false
class Test{
public static void main(String[] args){
Node<String> nc=new Node<>();
Comparable<String> com=nc;
}
________________________
true
list1.add(new Gum());
list2.add(new Integer(9));
System.out.println(list2.size());
}
____________________
2
34. Which of the following is the correct lexicographical order for the conents of
the following int array?
____________________________
{1, 1, 17, 22, 28, 29, 3, 50, 71, 83}
35. A sequential search is an iteration through the array that stops at the index
where the desired element is found. True or false?
_________________________
true
40. In a regular expression, {x} and {x,} represent the same thing, that the
preceding character may occur x or more times to create a match.
True or false?
__________________________
false
41. Consider that you are making a calendar and decide to write a segment of code
that returns true if the string month is April, May, June, or July. Which code
segment correctly implements use of regular expressions to complete this task?
__________________________
return month.matches("April|May|June|July");
43. Your teacher asks you to write a segment of code that returns true if String
str contains zero or one character(s) and false otherwise. Which of the following
code segments completes this task?(Choose Two)
____________________________
if( str.length() == 0 || str.length() == 1)
{ return true;}
return false; (*)
44. A non-linear recursive method can call how many copies of itself?
_______________________________
2 or more
45. A non-linear recursive method is less expensive than a linear recursive method.
True or false?
__________________
false
50. Identify the method, of those listed below, that is not available to both
StringBuilders and Strings?
_________________
delete(int start, int end)