C210 Midterm

Ace your homework & exams now with Quizwiz!

2. What is the role of a private modifier on a constructor? a. To prevent a class from being instantiated b. To evaluate a data field. c. To protect the integrity of the data stored in that class. d. All of the above.

A

3. "A extends B" and "C extends A" means B is a superclass to A and A is a superclass to C. a. True b. False

A

A default constructor is provided automatically only if... A. No constructors are explicitly defined in the class B. A constructor is explicitly defined in the class C. A no-arg constructor is explicitly defined in the class D. None of the above

A

A row and column index is used to access an element of which of the following? A. Two-Dimensional Array B. Object C. Primitive Type D. Single-Dimensional Array

A

Assume Midterm inherits Test's properties. Analyze the following code and select the correct statement: public class Midterm extends Test { private String question; private String answer; public Midterm (String question, String answer, String questionFormat) { setQuestion (question); setAnswer (answer); super (questionFormat); } } A. The code has a compile error. B. The code has a runtime error. C. The code is fine. D. The last line of code should be written as setQuestionFormat(questionFormat);.

A

Defining a new class from an existing class is an example of... A. Inheritance B. Abstraction C. Instantiation D. Declaring a Constructor

A

Q1: True or False? Unlike, arrays, which can store objects or values of primitive data types, ArrayLists store only objects. True False

A

Q2 Module 2: _____ Is resizable and is not fixed but when needed it can grow and shrink. A: ArrayList B: Static Method C: Java Library D: Java Array

A

Q2 on Module 3: A public no-arg constructor with an empty body is defined as a? A. Default Constructor B. Constructor C. Anonymous Object. D. Private Constructor

A

Q2 on Module#3: The special form of association that represents an ownership (has-a) relationship is called __________ . A. Aggregation B. Inheritance C. Abstraction D. Realization

A

Q2(Module 3): Which of the following statements are true? a. Static methods cannot be overridden b. Objects pass values to variables c. Constructors are inherited from parent classes by subclasses d. All of the above

A

Q2: If you do not want a class from being instantiated, you should use on the constructor. Private modifier Default modifier Protected modifier Public modifier

A

Q2: _____ is used to hide and protect the internal representation of an object, while also providing an interface to use said object. A. Encapsulation B. Aggregation C. Composition D. A wrapper class

A

Q3 Module 4: Which of the following is not true? A. A superclass's constructor is inherited B. A constructor is used to construct an instance of a class C. The keyword super refers to the superclass of the class in which super appears D. You must use the keyword super to call the superclass constructor.

A

Typically, it is important to keep ___________ private as they should not be accessed directly to avoid unwanted modification. A. Instance variables B. Static variables C. Modifiers D. Getter and setter methods

A

Upcasting an object can be done implicitly in Java because: 1. An object automatically inherits all properties and methods from a superclass/parent class in an 'is-a' relationship 2. Upcasting happens so frequently that explicitly upcasting each instance of a class would result in less readable code 3. A subclass has fewer properties and methods than its superclass 4. All typecasting can be done implicitly in Java

A

When creating a string value, if a value is not assigned then the the default value is set as? A. Null B. 0 C. Strings need a value to be created D. ""

A

Which of the following is not a way that a superclass constructor is invoked? a. Inheritance b. explicitly c. implicitly d. explicitly using the super keyword

A

Which statement is used for assigning the value 4 to a specific element at row 3 and column 1? A. matrix[2][0] = 4; B. matrix[3, 1] = 4; C. matrix[3][1] = 4; D. matrix [2, 0] = 4;

A

Without a modifier, a class can be accessed: From the same class and package From a subclass in a different package From a different package All the above

A

________ is the keyword used to declare a class. A. class B. static void C. public D. private

A

int[][] theArray = {{1,2,3},{4,5,6},{7,8,9},};System.out.println(theArray[1][1] == 5); true false 5 Does not compile

A

The client can use a method without knowing how it is implemented. The details of the implementation are encapsulated in the method and hidden from the client who invokes the method. This is known as __________. (Multiple answers possible enter X, Y) A. information hiding B. encapsulation C. method hiding D. simplifying method

A, B

Which of these items must be true when multiplying matrices? Select all that apply (Enter like X, Y) a. m1 and m2 must have compatible types of elements b. the number of columns in m1 must match the number of rows in m2 c. requires a third nested loop d. all dimensions of matrices must be the same

A, B

2. Which of the following statements is false? A. A primitive-type object value is not an object B. Aggregation may exist between objects of the same method C. Association describes an activity between two classes D. Two or more of these choices is correct

B

If you do not specify a toString() method in a class, will using toString() in reference to that class in your main method result in executable code? Why is that? a) Yes, any value can be converted to a String in Java. b) Yes, the object class in Java comes with a default toString() that will print an object's location. c) No, there will be a runtime error. d) No, there will be a compile error.

B

Q1 Module 2 Which of the following statements is false ? A. Multidimensional arrays are arranged as an array of arrays. B. Each element of a multidimensional array is not another array. C. The representation of the elements is in rows and columns. D. You get a total number of elements in a multidimensional array by multiplying row size with column size.

B

Q1 Module 2: Assume double[][] x = new double[4][5], what are x.length and x[2].length? A: 4 and 4 B: 4 and 5 C: 5 and 4 D: 5 and 5

B

Q1 Module 2: What array is considered to have rows with different lengths? A. Complex Array B. Ragged Array C. Initial Array D. Diverse Array

B

Q1 Module 2: Which is the correct Syntax for starting an Array List: A: ArrayList<Class_Name> someArrayList == new ArrayList<Class_Name>(); B: ArrayList<Class_Name> someArrayList = new ArrayList<Class_Name>(); C: Array [][] <Class Name> someArrayList = new ArrayList<Class_Name>(); D: ArrayList []<Class_Name> someArrayList = new ArrayList<Class_Name>();

B

Q1 on Module#2: Which of the following is NOT a valid way to initiate a three-dimensional array? A. double[ ][ ][ ] threeD = new double[5][3][ ]; B. double[ ][ ][ ] threeD = new double[ ][4][ ]; C. double[ ][ ][ ] threeD = new double[ ][ ][ ] { {{1.0, 2.0},{3.0, 1.0}}, {{5.0, 2.0},{3.0, 8.8}}, {{1.7, 9.4},{6.8, 1.0}}, {{1.0, 2.0},{3.0, 1.0}}}; D. double[ ][ ][ ] threeD = new double[8][ ][ ];

B

Q1. What is a common way to process two-dimensional arrays? A. Moving its contents into a temporary array. B. Using nested 'for' loops. C. Using a linear search. D. Using a binary search.

B

Q2 Module 2: Consider the following int [][] myArray = { {1, 2, 2, 4} , {3, 2, 8, 6}, {5, 9, 9, 7} } What is the value at myArray [2] [3]? A: 2 B: 8 C: 9 D: 4

B

Q2 Module 3: Which is an example of Aggregation? hugh = new Dog(); This.name = name; Fluffy instanceof Cat; weight = hugh.weight;

B

Q2 Module 3: __________ represents an entity in the real world that can be distinctly identified. A: A class B: An object C: A method D: A data field

B

Q2: True or False? While encapsulation is meant to show only essential features of the object, abstraction is meant to hide the object's members from the outside of the class. True False

B

Q2: Which of the following is the correct way to reference the item in the second row, first column in a 2-D array exampleArray? a. exampleArray[1][2] b. exampleArray[1][0] c. exampleArray[2][1] d. exampleArray[0][1]

B

Q3 Module 4: Feature that changes inherited methods in a subclass. A: Extends Class B: Method Overriding C: Encapsulation D: Math package

B

Q3 Module 4:Object-oriented programming allows you to derive new classes from existing classes. This is called ____________. A: encapsulation B: inheritance C: abstraction D: generalization

B

Q3: Static methods are not inherited by sub-classes and can be overriden. True False

B

Q3: What method is used to check how many elements are in an ArrayList? length() size() contains() None of the above

B

Q3: Where are private data fields in a superclass accessible? A: Directly in a subclass B: Public accessors/mutators defined in a superclass C: Anywhere outside of the class D: Classes the data field is not declared in

B

Unlike arrays which can store objects or values of primitive data types; ArrayList store ______. A. Objects and Primitive Data types B. Objects only C. Primitive Data Types only D. None of the above

B

What's the out put for the code segment below? ArrayList<Integer> list = new ArrayList<>(); list.add(1); list.add(2); list.add(3); list.remove(1); System.out.println(list); A: [2, 3] B: [1, 3] C: [1, 2] D: Compile error

B

When you declare an object, you are declaring a(an): object name reference variable primitive type instance name

B

Which is not a pillar of object oriented programming? A. Inheritance B. Super C. Polymorphism D. Encapsulation

B

Which is not a type of casting: Upcasting Roundcasting Explicit casting None of the above

B

Which of the following best describes the difference between an array and an arraylist: A. An array is a primitive datatype while an arraylist holds primitive datatypes B. An arraylist is a re-sizable array which holds objects while an array is fixed size C. An array is re-sizable while an arraylist is fixed size D. An array and an arralist are synonyms and are interchangeable

B

Which of the following is is not a unique part of an object? a. behavior b. method c. state d. identity

B

Which of the statements regarding the super keyword is incorrect? A. You can use super to invoke a super class method. B. You can invoke a method in superclass's parent class. C. You cannot use super.super.p to invoke a method in superclass's parent class. D. You can use super to invoke a super class constructor.

B

1. What is the maximum number of elements that can be stored in the following array: int[ ][ ] matrix = new int[7][4] ? a. 11 b. 17 c. 28 d. 35

C

A primitive-type value is not an object, but it can be wrapped in an object using a wrapper class in the Java API. Select the incorrect statement about wrappers. A. An Integer object wraps an int primitive type. B. A Double object wraps a double primitive data type. C. A Char object wraps a char primitive data type. D. A Boolean object wraps a boolean primitive data type.

C

A three-dimensional array is made up of: Exactly 3 single-dimension arrays Any amount of single-dimension arrays Two-dimensional arrays Table-arrays

C

ArrayLists are a Resizable-array implementation. The size of the ArrayList is not fixed and can grow and shrink dynamically as needed. When an ArrayList is constructed, what is the default initial capacity allocated for an empty list? A. 0 B. 8 C. 10 D. ArrayLists do not have a default capacity and the initial size must be specified with an initial capacity in the code.

C

Examine the following code and identify its output: /** for(int i = 1; i < 10; i++){ System.out.print("\n"); for(int j = 1; j < 10; j++){ System.out.print((i * j) + " "); } } **/ 1. A series of output strings that prints 'i * j' before creating a new line 2. A 2-dimensional array 3. A multiplication table 4. A method that traverses a 2-dimensional array and prints the arrays' odd numbers

C

Q1 Module 2: Consider: int numList[] = newArrayList(); numList.add(1, 2, 3, 4, 5, 7, 8, 9, 0); Question: What is the size of the array? 10 4 9 8

C

Q1 on Module 2: ____ is actually an array in which each element is a one-dimensional array. A. Java Array B. Array List. C. Two Dimensional Array D. Initial Array

C

Q1: What does an array initializer not do for a two-dimensional array? A: Initialize B: Declare C: Print D: Create

C

Q1: Which algebra operations are available to be performed on matrices? Addition Multiplication Both A and B Neither A nor B

C

Q1: Which of the following is TRUE about array? The size of an array is flexible The length and dimensions of an array can be declared anytime When passing an array to a method, a reference of an array is passed When passing an array to a method, a copy of the array is passed

C

Q1: Which of the following is false? A. ArrayLists can only store objects. B. Regular Java arrays are considered to be fixed-size data structures. C. When multiplying two matrices, the size of the rows and columns does not matter. D. When adding or multiplying matrices, the types of elements must be compatible.

C

Q2 Module 3: When an object is declared by a class type, the variable created is a _____ variable that refers to an object of that type. A: Static B: Void C: Reference D: Array List

C

Q2 Module#3 Which of these is the proper UML notation for Aggregation? a)-----> b)SOLID LINE WITH SOLID BLACK DIAMOND c)SOLID LINE WITH OPEN DIAMOND d)SOLID LINE WITH OPEN ARROW

C

Q2: Select the statement that is not criteria of a constructor. A: Invoked by using the new operator when a new object is created. B: Does not have a return type. C: Must have the void keyword before it. D: Must have the same name as the class itself.

C

Q2: What is used to instantiate objects of a class? Set method Get method Constructor toString()

C

Q3 Module 3: ____________ variables can be accessed by all objects of the class. A: Instance B: Private C: Static D: Random

C

Q3 Module 4 In a(n) ___________________ relationship, an object of a subclass can also be treated as an object of its superclass. A. has-a or Composition B. is-a or Aggregation C. is-a or Inheritance D. has-a or Inheritance

C

Q3 on Module#4 It is always possible to cast an instance of a subclass to a variable of a superclass (known as ________) because an instance of a subclass is always an instance of its superclass. A. Dynamic Building B. Downcasting C. Upcasting D. Encapsulation

C

Q3(Module 4): Which is true of Overloading and Overriding methods?: a. Overloading defines new implementation of a method b. Overridden methods are in the same class c. Overloaded methods have same names but different parameters d. They are the interchangeable terms

C

Q3. When downcasting, how can you avoid runtime errors? A. Use the 'toString' method. B. Use an ArrayList. C. Use the 'instanceof' operator. D. Use the 'clear()' method.

C

Q4 Module 3: In a class this is used to instantiate objects of the class? A: toString() B: UML Diagrams C: Constructor D: Private modifiers

C

Question 1: What is the syntax for declaring a two-dimensional array? A: arrayRefVar[] [] B: elementType[][] arrayRefVar; C: Both B and D D: elementType arrayRefVar[][];

C

Question 3: What are the three pillars of object-oriented programming? A: Polymorphism, subclass, and superclass B: Inheritance, Object, and Strings C: Encapsulation, inheritance, and polymorphism D: Dynamic binding, Encapsulation, and Objects

C

The following code results in an error. Select the reason why: public static void main(String []args){ class MyClass { int x; MyClass(double i ) { x = i; } } MyClass test = new MyClass(1); System.out.println(test.x); } } **/ 1. 'MyClass' does not contain an explicitly defined default constructor 2. 'MyClass' is not appropriately encapsulated 3. The 'MyClass' object 'test' was created with an argument of an incompatible type 4. 'MyClass' does not contain a 'toString' method

C

What is the output of the following code?.public class Test { public static void main(String[] args) {int[][][] data = {{{1, 2}, {3, 4}},{{5, 6}, {7, 8}}};System.out.print(ttt(data[0]));}public static int ttt(int[][] m) {int v = m[0][0];for (int i = 0; i < m.length; i++)for (int j = 0; j < m[i].length; j++)if (v < m[i][j])v = m[i][j];return v;}} A. 1 B. 2 C. 4 D. 5 E. 6

C

Which is not true about a multideminsional array? A. Each row in a multidimensional array is its own array B. Multidimensional arrays can be passed and returned from methods C. Array[1][1] reads the same as Array[1,1] D. Multidimensional arrays can contain more than 3 dimensions

C

Which of the following are true about constructors? A. A constructor does not have to have the same name as the class itself. B. A constructor has a return type - could be void. C. A constructor is invoked using the new operator when an object is created; initializing the object. D. A constructor cannot be overloaded.

C

Which of the following is NOT a fundamental programming structure? Sequential Control Decision Control Class Control Looping Control

C

1. When passing a two dimensional array to a method, the reference of the _______ is passed to the _________. A. array; array; B. method; array C. two dimensional array; one dimensional array D. array; method

D

3. Which of the following is incorrect about the keyword super? A. It can be used to call a superclass constructor B. The statement super() is used to invoke the no-arg constructor of its superclass C. It can be used to call a superclass method D. The statement super() is used to invoke the super class constructor that matches the arguments.

D

Q1 Module 2: Evaluate: public static double getAverage(int[][] array): A: this method returns the sum of all the values in an array passed to the method. B: this method returns the smallest value in the first row of a 2D array passed to it C: this method initializes the array to number 5 when the row value equals the columns value, otherwise it initializes it to zero D: this method returns the average of all the values in an array passed to the method.

D

Q1 Module 4: Which of the following modifiers suggest a particular method can only be accessed by its own distinct class? A: Protected B: Public C: Default or "no modifier" D: Private

D

Q1(Module 2): What is false about Multi-Dimensional Arrays? a. Values are passed by reference of the array b. Multi-Dimensional Arrays cannot have additional elements appended after initialization c. Should not have values evaluated or compared using boolean operators d. None of the above

D

Q1: When writing code to read all items in a list, always start with item number? a. -1 b. 1 c. It does not matter d. 0

D

Q2 Module 3 Set methods are commonly called__________________ because they typically change a value. A. accessor methods B. query methods C. get methods D. mutator methods

D

Q2 Module 3: When will a class have a default constructor? A. When no constructors are defined in the class B. When to many constructors are defined in a class C. When an empty body with a public no-arg constructor is defined D. Both A and C

D

Q2. When two objects are associated by a has-a relationship, this is know as: A. Abstraction B. Object-oriented programming C. Primitive types D. Aggregation

D

Q3 Module 3: A class usually defines and ______ the fields that are used to store data A: Type B: reference variable C: Evaluates D: Encapsulates

D

Q3 Module 4: Which is true about final classes? They can be abstract They can be extended They can be edited outside of the class They cannot be sub-classed

D

Q3 on Module 4: The capability allows you to derive a subclass from several classes. A. Method Overriding B. Single inheritance C. Constructor Chaining D. Multiple inheritance

D

Q3 on Module#4: Choose the list of member accessibility modifiers that is in order from least restricted to most restricted: A. Public, Default, Protected, Private B. Default, Public, Protected, Private C. Public, Protected, Private, Default D. Public, Protected, Default, Private

D

Q3: What should be applied to a class to prevent the class being extended? a. native b. abstract c. final d. private

D

Q3: Which of the following is FALSE? You can use instanceof operator after you perform downcasting A public class can only be accessed by a class within the same package A private class can be accessed by a subclass in the same package A protected class can be accessed by a subclass in a different package

D

Q3: Which of the following is true? A. A superclass is also referred to as a derived class. B. Inheritance represents a "has-a" relationship. C. A subclass only inherits properties and methods from its direct superclass. D. Java only supports single inheritance; multiple inheritance is not allowed.

D

Question 2: The ____________ method returns the number of characters actually stored in the string builder. A: Capacity( ) B: Set Length( ) C: CharAt( ) D: Length( )

D

The key word super is used to denote: A. A child class B. Encapsulation C. Overriding D. A parent class

D

What is the advantage of using ArrayList? a) ArrayList is dynamic, and can be updated both procedurally within the code and by user input b) ArrayList can store objects, not just primitive data types c) The size of ArrayList can be specified to an initial condition and can change in size as needed d) All of the above

D


Related study sets

Lesson 8: Embryonic & Fetal Development, Pregnancy, Parturition, & Lactation

View Set

Unit One Psychology Practice Test Questions

View Set

(QUIZ) Finance Skills for Managers - D076

View Set

NCIDQ Class 2 HW - Codes, Building Systems & Construction

View Set

Driver's Ed- Consumer Responsibility

View Set