CIS 265 - Spring 2015 Exam-1

CIS 265 - Spring 2015 Exam-1

<p>CIS 265 - Spring 2015 Exam-1 Fist Name______Last Name______</p><p>MULTIPLE CHOICE. (25points) Choose the one alternative that best completes the statement or answers the question. 1) The following code displays ______. double temperature = 50; if (temperature >= 100)</p><p>System.out.pri ntln("too hot"); else if (temperature <= 40)</p><p>System.out.pri ntln("too cold"); else</p><p>System.out.pri ntln("just right");</p><p>1) ______just right B) too cold too hot D) too hot too cold just right </p><p>Which of the following is the correct expression that evaluates to true if the number x is between 1 and 100 or the number is negative? 2) ______(1 > x > 100) || (x < 0) 1 < x < 100 && x < 0 ((x < 100) && (x > 1)) && (x < 0) ((x < 100) && (x > 1)) || (x < 0) </p><p>To check whether a char variable ch is an uppercase letter, you write ______. 3) ______(ch >= 'A' && ch >= 'Z') B) (ch >= 'A' && ch <= 'Z') ('A' <= ch <= 'Z') D) (ch >= 'A' || ch <= 'Z') </p><p>What is the output for y? int y = 0; for (int i = 0; i<10; ++i) { y += i; } System.out.pri ntln(y);</p><p>4) ______12 B) 45 C) 11 D) 13 E) 10 </p><p>What is sum after the following loop terminates? int sum = 0; int item = 0; do { item++; sum += item; if (sum >= 4) continue; } while (item < 5);</p><p>5) ______16 B) 15 C) 17 D) 18 </p><p>If you declare an array double[ ] list = {3.4, 2.0, 3.5, 5.5}, the highest index in array list is ______. 6) ______0 B) 2 C) 1 D) 4 E) 3 </p><p>If you declare an array double[ ] list = {3.4, 2.0, 3.5, 5.5}, list[1] is ______. 7) ______2.0 3.4 5.5 3.4 undefined 8 ) </p><p>In the following code, what is the printout for list2? class Test { public static void main(String[ ] args) { int[ ] list1 = {1, 2, 3}; int[ ] list2 = {1, 2, 3}; list2 = list1; list1[0] = 0; list1[1] = 1; list2[2] = 2; for (int i = 0; i < list2.length; i+ +)</p><p>System.out.pri nt(list2[i] + " "); } }</p><p>8) ______1 2 3 B) 0 1 2 C) 1 1 1 D) 0 1 3 </p><p>______represents an entity in the real world that can be distinctly identified. 9) ______An object B) A data field A method D) A class </p><p>10) Analyze the following code: public class Test { public static void main(String[ ] args) { int[ ] x = {1, 2, 3, 4}; int[ ] y = x;</p><p> x = new int[2];</p><p> for (int i = 0; i < y.length; i++)</p><p>System.out.pri nt(y[i] + " "); } }</p><p>10) ______The program displays 0 0 0 0 B) The program displays 0 0 The program displays 1 2 3 4 D) The program displays 0 0 3 4 </p><p>11) ______is a construct that defines objects of the same type. 11) ______A class B) A data field A method D) An object </p><p>12) An object is an instance of a ______. 12) ______data B) program C) class D) method </p><p>13) ______is invoked to create an object. 13) ______A constructor A method with the void return type The main method A method with a return type </p><p>14) Given the declaration Circle[ ] x = new Circle[10], which of the following statement is most accurate? 14) ______x contains a reference to an array and each element in the array can hold a reference to a Circle object. x contains a reference to an array and each element in the array can hold a Circle object. x contains an array of ten objects of the Circle type. x contains an array of ten int values. </p><p>15) What is the output of the following code? String s = "University"; s.replace("i", "ABC"); System.out.pri ntln(s);</p><p>15) ______University B) UnABCversity UniversABCty D) UnABCversABCty </p><p>16) You can create an ArrayList using ______. 16) ______new ArrayList[100] B) new ArrayList[ ] ArrayList() D) new ArrayList() </p><p>17) Object- oriented programming allows you to derive new classes from existing classes. This is called ______. 17) ______abstraction B) generalization encapsulation D) inheritance </p><p>18) What is the return value of "SELECT".sub string(0, 5)? 18) ______"SELECT" B) "SELE" "SELEC" D) "ELECT" </p><p>19) Invoking ______removes all elements in an ArrayList x. 19) ______x.clean() x.remove() x.delete() x.clear() x.empty() </p><p>20) Suppose ArrayList x contains two strings [Beijing, Singapore]. Which of the following methods will cause the list to become [Beijing, Chicago, Singapore]? 20) ______x.add(1, "Chicago") B) x.add(0, "Chicago") x.add(2, "Chicago") D) x.add("Chicago") </p><p>21) Invoking ______returns the first element in an ArrayList x. 21) ______x.get(1) B) x.get() C) x.get(0) D) x.first() </p><p>22) Invoking ______returns the number of the elements in an ArrayList x. 22) ______x.length(1) B) x.size() x.getSize() D) x.getLength(0) </p><p>23) Inheritance means ______. 23) ______that data fields should be declared private that a variable of supertype can refer to a subtype object that a class can extend another class that a class can contain another class </p><p>24) Composition means ______. 24) ______that a class can contain another class that data fields should be declared private that a variable of supertype can refer to a subtype object that a class can extend another class </p><p>25) Encapsulation means ______. 25) ______that a class can contain another class that a variable of supertype can refer to a subtype object that data fields should be declared private that a class can extend another class </p><p>1 ) A 2 ) D 3 ) B 4 ) B 5 ) B 6 ) E 7 ) A 8 ) B 9 ) A 1 ) 0 C 1 ) 1 A 1 ) 2 C 1 ) 3 A 1 ) 4 A 1 ) 5 A 1 ) 6 D 1 ) 7 D 1 ) 8 C 1 ) 9 D 2 ) 0 A 2 ) 1 C 2 ) 2 B 2 ) 3 C 2 ) 4 A 2 ) 5 C</p><p>Exam 1 KEY 1) A 2) D 3) B 4) B 5) B 6) E 7) A 8) B 9) A 10) C 11) A 12) C 13) A 14) A 15) A 16) D 17) D 18) C 19) D 20) A 21) C 22) B 23) C 24) A 25) C</p>

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    252 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us