Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

1. (6 points) Which of the following is a legal way to declare and create an array of 10 String objects? a. String s =

1. (6 points) Which of the following is a legal way to declare and create an array of 10 String objects? a. String s = new String(10); b. String[10] s = new String; c. String[ ] s = new String[10]; d. String s = new String[10]; e. String[ ] s = new String;

2. (8 points) Consider the array declaration and creation: int[ ] arr = new int[5]; Which of the following is true about arr? a. It stores 5 elements with legal indices between 1 and 5 b. It stores 5 elements with legal indices between 0 and 4 c. It stores 4 elements with legal indices between 1 and 4 d. It stores 6 elements with legal indices between 0 and 5 e. It stores 5 elements with legal indices between 0 and 5

3. (6 points) To declare a three-dimensional int array called threeD, which of the following would you use? a. int[3] threeD; b. int[ , , ] threeD; c. int[ ][ ][ ] threeD; d. int[ [ [ ] ] ] threeD; e. int[ ] threeD[3];

4. (6 points) What are some problems with fixed-size array declaration (created with a literal constant value)? a. Some space may be wasted b. The program cant adjust if the number of elements is more than the specified size

c. The program needs to be recompiled to accommodate more elements d. All of the above

5. (6 points) To swap the 3rd and 4th elements in the int array values, you would do: values[3] = values[4]; values[4] = values[3]; a. TRUE b. FALSE

6. (8 points) What will be an output from the following code? int[] list = {10, 20, 30, 40}; myMethod(list); System.out.print(list[1]); System.out.print(list[3]); ... public void myMethod(int[] intArray) { for (int i=1; i < intArray.length; i+=2) { intArray[i] = 4010*i; } } a. 4020 b. 1030 c. 3010 d. 2040 e. 1040

7. (6 points) When arrays are passed to a method as arguments: a. All elements of the array are copied b. Only the first element is copied and others are derived from it c. The elements are not copied, but the address is copied d. Both the elements and the address are copied e. None of the above

8. (4 points) In creating an array of objects, you have to create the array, and you must also instantiate each element object thats stored in the array. a. TRUE b. FALSE

9. (6 points) Assume values is an int array that is currently filled to capacity, with the following values: 9 4 12 2 6 8 18 What is returned by values[3]? a) 9 b) 12 c) 2 d) 6 e) 3

10. (8 points) How many double values will the following array hold? double[][] newArray = new double[4][]; for(int i=0; i < 4; i++) newArray[i] = new double[i+1]; a. 16 b. 4 c. 14 d. 8 e. 10

11. (8 points) What would be the outcome of the following code: double[] number = new double[25]; for (int i=0; i < number.length; i++) number[i] = i; System.out.println(number[25]); a. 25 (printed to standard console) b. 0 (printed to standard console) c. Exception d. Dynamic allocation of memory e. None of the above

12. (4 points) It is legal to store int values and also double values in a single standard array. a. TRUE b. FALSE

13. (8 points) What does the following code do? Assume list is an array of int values, temp is some previously initialized int value, and c is an int initialized to 0. for (j=0; j < list.length; j++) if (list[j] < temp) c++; a. It finds the smallest value and stores it in temp b. It finds the largest value and stores it in temp c. It counts the number of elements equal to the smallest value in list d. It counts the number of elements in list that are less than temp e. It sorts the values in list to be in ascending order

14. (8 points) Fill in the blank in the following code fragment so that each element of the array is assigned twice the value of its index. int[] array = new int[10]; for (int index=0; index < array.length; index++) { _______________________ } a. index = 2*index; b. array[ 2*index ] = 2*index; c. array[ index ] = 2*array[ index ]; d. array[ index ] = 2*index;

15. (6 points) To determine the number of items stored in an ArrayList object, you use this method. a. size b. capacity c. items d. length

16. (4 points) Given a declared and created array thats named myArray, you can access the first element in the array using the indexed expression myArray[0]. a. TRUE b. FALSE

17. (4 points) The value of an arrays length equals the value of the arrays largest acceptable index. a. TRUE b. FALSE

18. (6 points) What is the relationship between an object and a class? a. An object and a class can be used interchangeably b. A class is an instance of an object c. An object is a template for a class d. An object is an instance of a class e. None of the above

19. (6 points) The behavior of an object is defined by the objects a. instance data b. constructor c. visibility modifiers d. methods e. all of the above

20. (8 points) Which of the following statements best describes inheritance? a. Inheritance is the process of creating a new object b. Inheritance is used to organize a program for maintainability c. Inheritance is used when you need to create many objects of the same type d. Inheritance is used to design two or more entities that are different but share many common features

e. Inheritance refers to the process of creating two methods that have the same name but different return types or arguments

21. (6 points) What is the underlined word mean in Java given the following method? public void test() { } a. It means that this method does not return anything b. It means that this method will return a variable of type void c. It means that this method should no longer be used d. It means that this method cant be accessed

22. (4 points) You can make a variable defined within a method be available outside that method by including the word public in that variable's declaration. a. TRUE b. FALSE

23. (6 points) In Java a variable may contain a. A value or a reference b. A package c. A method d. A class e. Any of the above

24. (6 points) A method that accesses an object and returns some information about it, without changing the object, is called a(n) ____ method. a. explicit b. implicit c. mutator d. accessor

25. (6 points) This is the method that is automatically called when an instance of a class is created. a. accessor b. constructor c. void d. mutator

26. (6 points) Two or more methods of a class may have the same name as long as this is different. a. Their return values b. Their access specifier c. Their parameter lists d. Their memory address

27. (8 points) What is the output of the following code? Weight wgt1 = new Weight(1234.56); Weight wgt2 = new Weight(1234.56); boolean result1 = wgt1 == wgt2; boolean result2 = wgt1.equals(wgt2); System.out.print(result1); System.out.println(result2); a. false true b. true false c. false false d. true true e. Nothing, the code is invalid

28. (8 points) Order the sequence of steps used in using objects: 1. Declare an object 2. Define a class 3. Create an object 4. Send a message to the object a. 1, 2, 3 and 4. b. 2, 3, 1 and 4. c. 2, 1, 3 and 4. d. 2, 1, 4 and 3.

29. (8 points) Which of the following describes the way that objects are passed as parameters or returned from methods? a. The whole objects are copied both to and from the methods b. Only the addresses are copied into the method, but the whole object is copied out on return c. In both cases, the address is copied d. Only the addresses are copied out, but the whole object is copied into e. None of the above

30. (8 points) Every method definition contains the following parts: ____. a. the return type, the name of the method, and a list of the parameters (if any) b. an access specifier, a list of the parameters (if any), and the body of the method c. an access specifier, the return type, the name of the method, a list of the parameters (if any), and the body of the method d. an access specifier and the return type

31. (6 points) The following method header definition will result in a syntax error: public void aMethod( ); a. TRUE b. FALSE

32. (8 points) Consider a method defined with the header: public void foo(int a, int b) Which of the following method calls is legal? a. foo(0, 0.1); b. foo(0 / 1, 2 * 3); c. foo(0); d. foo( ); e. foo(1 + 2, 3 * 0.1);

33. (4 points) All Java classes must contain a main method which is the first method executed when the Java class is called upon. a. TRUE b. FALSE

34. (4 points) Accessors and mutators provide mechanisms for controlled access to a wellencapsulated class. a. TRUE b. FALSE

35. (4 points) If the name of an argument in a method call is the same as the name of the corresponding parameter in the method's definition, changing that parameter's value inside the method also changes the value of the corresponding argument in the calling program. a. TRUE b. FALSE

36. (8 points) Consider an object, myObj, of class MyClass. The private data members of myObj can be accessed by: a. methods in myObj, but not other objects b. class methods of MyClass c. nobody, including myObj d. none of the above

37. (6 points) A variable whose scope is restricted to the method where it was declared is known as a(n) a. parameter b. global variable c. local variable d. public instance data e. private instance data

38. (6 points) What is true about the new operator? a. It is used in class declarations b. It is used to create a new object c. The keyword new does not exist in Java d. a and b e. None of the above

39. (6 points) The purpose of a constructor is: a. to call a method before any message can be sent to it b. to define methods other objects cannot access c. to define methods only the class can access d. to initialize the object to a valid state e. All of the above

40. (4 points) The difference between the throw reserved word and the throws reserved word is that throw is used within a method body, while throws is used within a method header. a. TRUE b. FALSE

41. (6 points) The isDigit, isLetter, and isLetterOrDigit methods are members of this class. a. String b. Char c. Character d. StringBuilder

42. (6 points) What situation makes an object eligible for garbage collection? a. When it has not been initialized to a valid state. b. When it has been declared, but not created. c. When it has no more references to it. d. When it has reached the limit of methods calls to it. e. None of the above.

43. (4 points) For each class Java automatically provides a zero-parameter constructor that is always available unless you override it with an explicitly defined zero-parameter constructor. a. TRUE b. FALSE

44. (6 points) The least encapsulated type of variable is a(n) _____________ variable. a. Local b. Instance c. Class d. Constant

45. (4 points) Using Java API methods saves programming time and improves program quality. a. TRUE b. FALSE

46. (6 points) You use this statement to throw an exception manually. a. try b. generate c. throw d. System.exit(0) e. getError

47. (4 points) All Java API methods are class methods. a. TRUE b. FALSE

48. (6 points) Stubs are used with: a. Top down design b. Bottom up design c. Iterative enhancement d. All of above

49. (6 points) This is one of the methods that are common to both the String and StringBuilder classes. a. append b. insert c. delete d. length e. all of the above

50. (4 points) Save time by deferring all testing to the end of a development process. a. TRUE b. FALSE

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions