CS38-Summer 2009-Final Exam_Solution

CS38-Summer 2009-Final Exam_Solution - Shouseman Page 1...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Shouseman Page 1 10/5/2011 JAVA- Final Exam-Solution Time allowed 2 hours Total = 20 points. Instruction: Complete all 40 multiple choice questions (0.5 POINT EACH), by marking the correct answer on Scranton (Form No. 882-E). Use a Pencil. 1. Which of the following for loops is valid, given the following declaration? String[] names = {“abc”, “def”, “ghi”, “jkl”}; A. for( int i = 0; i < names.length(); i++ ) System.out.println(names[i].length ()); B. for( int i = 0; i < names.length(); i++ ) System.out.println(names[i].length ); C. for( int i = 0; i < names.length; i++ ) System.out.println(names[i].length ()); D. for( int i = 0; i < names.length; i++ ) System.out.println(names[i].length); 2. When formulating a recursive solution, what should you consider? A. A recursive method that generate the base method object. B. We should consider the base case only. C. Consider base cases and general cases that are part java.recursion package D . Base cases and general cases. 3. The following statement creates an ArrayList object. What is the purpose of the <String> notation? ArrayList<String> arr = new ArrayList<String>(); A.    It specifies that   String   objects may not be stored in the   ArrayList              object. B.    It specifies that everything stored in the    ArrayList    object will be converted to   String .
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Shouseman Page 2 10/5/2011 C. It specifies that only String objects may be stored in the    ArrayList object . D. It specifies that only get method will return only String objects. . 4. Code that could generate a/an ___________________, such as an I O Exception, must be coded within a ____________. This is required. A. Checked exception, catch block B. Unchecked exception, try block. C. Checked exception, finally block D. None of the above 5. You coded the following in the class Test.java ; import java.io.IOException; import java.io.File; import java.util.Scanner; public class Test { public static void main (String [] args) { try { Scanner file = new Scanner (new File( “data.txt”)); String stringRead = file.nextLine(); } catch (IOException ioe) { ioe.printStackTrace(); } System.out.prinln( “String read: “ + stringRead); // line above is line 19 } } At Compile Time, you get the following error: Test.java:19: cannot find symbol symbol : variable stringRead location: class Test System.out.prinln( “String read: “ + stringRead); ^ 1 error Explain what the problem is and how to fix it: A. The catch block is not associated with the try block; you need to change the catch block as follows; catch (FileNotFoundException fnfe ) { fnfe.printStackTrace( );
Background image of page 2
Shouseman Page 3 10/5/2011 } B. This is an checked exception, there is no need for try or catch block C . Declare and initialize the variable stringRead before the try block. D.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/05/2011 for the course CS 38 taught by Professor Stevehouseman during the Summer '09 term at Irvine Valley College.

Page1 / 10

CS38-Summer 2009-Final Exam_Solution - Shouseman Page 1...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online