CS126 Test 3 Questions (Quiz 7-9 Questions)

Ace your homework & exams now with Quizwiz!

A.compareTo(B) will return 0 if: A. A and B are equal. B. A comes before B in ordering. C. B comes before A in ordering. D. There is an error while comparing. E. None of the Above.

A

TreeSet uses an internal linked data structure called what, to store its elements in order? A. Binary search tree. B. Octal search tree. C. Ordered search tree. D. Set search tree. E. Linked search tree.

A

What does the Java keyword these mean A. These is not a special keyword. B. It focuses on essential properties of the program. C. It hides the implementation details of an object. D. It allows you to refer to the implicit parameter inside a class. E. None of the given definitions

A

What happens if a class claims to be a Shape but doesn't implement the area and perimeter methods? A. The program will not compile. B. The program will run but produce an exception. C. The program will run successfully. D. The program will automatically implement those methods for the user. E. All of the above.

A

Fill in the blanks in this definition: Polymorphism is the ability for ___ code to be used with ___ types of objects and behave ___ with each. A. the same, the same, differently B. different, the same, the same C. the same, different, differently D. different, different, differently E. the same, the same, the same

C

How do you call an overridden method? A. override.<method name>(<expression>) B. ride.<method.name>(<expression>) C. super.<method name>(<expression>) D. sub.<method name>(<expression>) E. None of the above.

C

The legal indexes of an ArrayList are between 0 and ____. A. The list's size() + 1 B. The list's size() C. The list's size() - 1 D. The list's size() - 2 E. None of the Above.

C

The method for the set operation "difference" is what? A. addAll. B. retainAll. C. removeAll. D. containsAll. E. There are no set operations.

C

What are the objects stored in a collection referred to as? A. Variables B. Data C. Elements D. Pointers E. None of the Above.

C

What coordinates does a Point store? A. None. B. x. C. x,y. D. x,y,z. E. Infinite.

C

What does add(index, value) do? A. Adds index, and value. B. Takes the parameters, and replaces them with variables, then adds them. C. Adds the given value at the given index. D. removes every element from a list. E. None of the above.

C

What does the Map method "values()" return? A. A Map. B. A Set. C. A Collection. D. A ArrayList. E. A boolean.

C

What is a Collection? A. A group in which the last element added is the first one to be removed. B. A group of elements that is guaranteed to contain no duplicates. C. An object that stores a group of other objects, called its elements. D. An object that stores only data. E. None of the above.

C

What is a header without implementation called in java? A. abstract header B. header method C. abstract method D. void header E. abstract void

C

What is a mutator? A. An instance method that modifies the data stored in an array to one specified by the user B. An instance method that changes the data type of an object C. An instance method that modifies the object's internal state D. An instance method that provides information about the state of an object without modifying it E. None of the Above

C

What is a superclass? A. A class that returns values to another class B. The child class in an inheritance relationship C. The parent class in an inheritance relationship D. A public class that extends an object E. None of the above

C

What is a superclass? A. The lowest class in a n inheritance relationship. B. The highest class in an inheritance relationship. C. The parent class in an inheritance relationship. D. The child, or derived, class in an inheritance relationship. E. None of the above.

C

What is an abstract method? A. An implementation with a header. B. A header with an implementation. C. A header without an implementation. D. An implementation without a header. E. None of the above.

C

What is object-oriented programming? A. Programs that perform their behavior independently. B. Programs that perform only when connected together. C. Programs that perform their behavior as interactions between objects. D. Programs that perform their behavior under specific circumstances. E. None of the above.

C

What is the result of the following code? ArrayList<String> list = new ArrayList<String>(); list.add("Hello"); list.add("World!"); list.add("Java"); list.add("Python"); list.add("CSharp"); list.remove(0); list.remove(2); System.out.println(list); A. [World!, Python, C Sharp] B. [World!, Java, Python] C. [World!, Java, C Sharp] D. [Hello, World!, Java] E. Error, since there is a space in "C Sharp"

C

What type of class typically provides implementation for abstract methods? A. Subclass B. Parent class C. Abstract class D. Method class E. None of the above

C

When declaring an ArrayList, what kind of syntax is <>? A. A relational operator. B. A parameter. C. A diamond operator. D. An array pointer. E. A rhombus operator.

C

When using the remove method in mapping, what does it remove? A. The map. B. The value. C. The key and value. D. The key. E. All of the above.

C

Which of the following is NOT a method of the Collection Interface? A. contains(element) B. addAll() C. containAll(collection) D. retainAll(collection) E. iterator()

C

What is substitutability? A. An object cannot reach its subclass. B. An object can reach its subclass. C. The inability of an object of a subclass to be used successfully anywhere an object of the superclass is expected. D. The ability of an object of a subclass to be used successfully anywhere an object of the superclass is expected. E. None of the above.

D

What problems would a large-scale project face? A. Getting programmers to work together. B. Getting code finished on time. C. Avoiding redundant code and fixing bugs. D. Maintaining, improving, and reusing existing code. E. All of the above.

E

Which cannot be a type of ArrayList? A. String. B. Point. C. Color. D. Integer. E. All of the above can be.

E

Which if statement checks if an object is greater than or equal to another object? A. if (x.compareTo(y) >= -1) {} B. if (x.compareTo(y) > 0) {} C. if (x.compareTo(y) >= 1) {} D. if (x.compareTo(x) >= 0) {} E. if (x.compareTo(y) >= 0) {}

E

Which is a benefit of a LinkedList? A. Adding and removing at either the beginning or end of the list is fast. B. Adding and removing during a sequential access with an iterator is fast. C. There is no need to expand when full. D. Can be more easily used as a queue. E. All of the above.

E

Which is an example of a collection? A. list B. stack C. queue D. map E. All of the above.

E

Which is not a method of the collection interface? A. isEmpty() B. iterator() C. toArray() D. clear() E. All of the above.

E

Which is not a method of the object class? A. clone() B. toString() C. equals(obj) D. hashCode() E. read()

E

Which of the following is NOT a basic ArrayList Method? A. add(index, value) B. size() C. add(value) D. clear() E. remove(index, value)

E

Which of the following is an issue that a large-scale computer project faces? A. Maintaining, improving, and reusing existing code. B. Finding and fixing bugs. C. Getting code finished on time. D. Getting many programmers to work together. E. All of the above are issues.

E

Which of the following lines is the proper way to implement an interface? A. public class <interface> implements <name> { B. public class <name> implements class <interface> { C. public <interface> implements class <name> { D. public <name> implements class <interface> { E. public class <name> implements <interface> {

E

What is an example of encapsulation? A. using a iPod. B. driving a car. C. changing the channel using a remote. D. taking a picture on your phone. E. All of the above.

E

What is a "Map"? A. A collection of key/value pairs in which each key is associated with a corresponding value B. An ordered collection of elements, often accessed by integer indexes or by iteration C. A collection in which elements are removed in the same order in which they were added D. A collection of integers that are associated with an array of the corresponding value E. A collection in which elements are removed in the same order in which they were added

A

What is a Wrapper Class? A. A class that stores primitive data as an object B. A class that converts primitive data to an object C. A class that stores objects as primitive data D. A class that encapsulates another program E. All of the Above

A

What is a field? A. A variable inside an object that makes up part of its internal state. B. A variable outside of an object that makes up part of its external state. C. A method that is inside an object that operates on that object. D. A method that is outside an object that operates on that object. E. None of these definitions.

A

What is a map? A. A collection of key/value pairs in which each key is associated with a corresponding value. B. A collection of elements that is guaranteed to contain no duplicates. C. A collection in which elements are removed in the same order in which they were added. D. A collection in which the last element added is the first one to be removed. E. An ordered collection of elements, often accessed by integer indexes or by iteration.

A

What is an interface? A. a list of methods that a class can implement. B. An interactive menu. C. A computers way of showing information on screen. D. A user friendly interactive window. E. All of the above.

A

What is one thing ArrayList, and LinkedList have in common? A. They are both fast when it comes to adding at the end of the list. B. They both have random access. C. They are both fast when it comes to adding at the beginning of the list. D. They can be used as a que. E. All of the above.

A

What is polymorphism in coding? A. The ability for a code to be used with several different object types and have it behave different depending on the type B. The ability for a function to be universal and can be effectively used in any code C. The ability for a class to be called in a different code D. The ability to make a universal variable for a group of classes E. None of the above

A

What is the grammar of a language? A. A description of a language that describes which sequences of symbols are allowed in that language. B. A description of a language that describes the semantics of the language. C. A description of a language that describes the portability of the language. D. A description of a language that describes what systems a language is compatible with. E. All of the Above.

A

What is the syntax for declaring encapsulated fields with an initial value? A. private <type> <name> = <value>; B. protected <type> <name> = <value>; C. private <type> <name>; D. protected <type> <name>; E. private static <type> <name> = <value>;

A

What is the ultimate superclass? A. Object B. toString C. fgetc D. getClass E. Clone

A

What must be used to access the elements of Sets and Maps? A. foreach loop B. index C. retrieve() D. for loop E. None of the Above.

A

Which line correctly declares a class as a subclass of another class? A. public class <name> extends <superclass> { B. public class <name> extends <subclass> { C. public class <subclass> extends <superclass> { D. public class <superclass> extends <name> { E. public class <subclass> extends <name> {

A

Which of the following methods can place a value within the middle of an ArrayList? A. add B. clear C. get D. place E. replace

A

A set's values must be ______. A. Copies B. In pairs C. Unique D. Characters E. None of the Above.

C

What is a class used for? A. main and other static method. B. an object class. C. a module. D. a large program. E. All of the above.

E

In ____Set, elements are stored in an unpredictable order. A. Oak B. Hash C. Tree D. Pound E. None of the Above.

B

In a subclass, how do you override a method that replaces the superclass's version? A. Use the override command. B. Write a new version of it in the subclass. C. Use command line arguments. D. Write a new version of it in the superclass. E. Methods cannot be overridden in any way.

B

What does a mutator do? A. Modifies an array. B. Modifies an object's state. C. Modifies a variable. D. Modifies a method. E. All of the above.

B

What does lastIndexOf(value) return if the value is not found? A. '\0' B. -1 C. 1 D. 0 E. null

B

What is Object-Oriented Programming? A. A programming entity that contains state (data) and behavior (methods). B. Reasoning about a program as a set of objects rather than as a set of actions. C. A set of values (internal data) stored in an object. D. A set of actions an object can perform, often reporting or modifying its internal state. E. None of these definitions.

B

What is a Is-a Relationship? A. A heirarchical connection between four categories in which one type is a specialized version of the others. B. A heirarchical connection between two categories in which one type is a specialized version of the other. C. A set of hierarchical relationships between classes of functions. D. A set of hierarchical relationships between classes of objects. E. None of the these.

B

What is a Java keyword that allows you to refer to the implicit parameter inside a class? A. here B. this C. eval D. now E. extend

B

What is a list of methods that a class can implement? A. Inheritance B. Interface C. Subclass D. Polymorphism E. Superclass

B

What is a map? A. A paper with locations on it. B. A collection that associates objects called keys with objects called values. C. A collection that associates objects called values with objects called keys. D. An ADT that has various operations and parameters. E. None of the above.

B

What is a reusable piece of software, stored as a class? A. program. B. module. C. main. D. shadowing. E. None of the above.

B

What is a set of hierarchical relationships between classes of objects? A. Stacked Hierarchy B. Inheritance Hierarchy C. Genetic Hierarchy D. Transfer Hierarchy E. None of the above

B

What is another word for nonabstract classes? A. stable class B. concrete class C. cement class D. final class E. None of the above

B

What is null? A. Zero. B. A value that does not refer to any objects. C. An unusable variable. D. An immutable object. E. None of the above.

B

What is substitutability? A. The ability of an object of a subclass to be used successfully anywhere an object of the subclass is expected B. The ability of an object of a subclass to be used successfully anywhere an object of the superclass is expected C. The ability for code to behave differently depending on the actual type of object used D. The ability for the same code to be used with several different types of objects E. All of the Above

B

What is the ability for the same code to be used with different types of objects and behave differently with each? A. pseudocode. B. polymorphism. C. is-a relationship. D. code reuse. E. None of the above.

B

What is the correct syntax for declaring an interface in java? A. public static void interface <name> B. public interface <name> C. private void <name> interface D. public <name> interface E. None of the above

B

What is the difference between a List and a Set? A. A List has a collection of key/value pairs. B. A Set is guaranteed to contain no duplicates. C. A List has the add() method and a Set does not. D. A Set has an iterator and a List does not. E. No difference.

B

What is the output of the following code? ArrayList<Integer> nums = new ArrayList<>(); nums.add(1); nums.add(2); System.out.println(nums.get(1)); A. 1 B. 2 C. Out of index compile error. D. 2 statements on the same line error. E. Syntax error.

B

What is the syntax for calling an interface? A. public type name (type name; ...; type name); B. public type name (type name, ..., type name); C. public type name (type name ... type name); D. public type name(type name, ... type name); E. public type name(type name, ..., type name):

B

When creating an ArrayList, it must be of what type? A. primitive B. object C. int D. null E. None of the Above.

B

Which of the following is an Iterator Object method that can return "true"? A. hasNextLine() B. hasNext() C. next() D. remove() E. canRemove()

B

Which returns the index of the last occurrence of the given value in the list (-1 if not found)? A. last.IndexOf(value) B. lastIndexOf(value) C. contains(value) D. indexOf(value) E. None of the above.

B

An implicit parameter is _____. A. The method on which an instance method is called. B. Placed within an explicit parameter. C. Used in explicit programs. D. The object on which an instance method is called. E. None of the above.

D

An inheritance hierarchy is a set of classes connected by what type of relationships that can share common code? A. superclass relationship B. is-it relationship C. inheritance relationship D. is-a relationship E. subclass relationship

D

Elements in lists are accessible by a _-based index. A. 1 B. -1 C. 2 D. 0 E. None of the Above.

D

How do you declare an abstract class in Java? A. public class abstract <name> B. public abstract <name> class C. abstract <name> class extends Object D. public abstract class <name> E. public abstract class <name> extends Object

D

To return true in an ArrayList, what do you use? A. true. B. indexOf(value). C. lastIndexOf(value). D. contains(value). E. All of the above.

D

What does the following code do import java.awk.*; Point p = new Point(4,6); p.translate(5, -3); A. It creates a point with x = 4 and y = 6, then translates it by adding 5 to x and subtracting 3 from y B. It creates a point with x = 6 and y = 4, then translates it by adding 5 to x and subtracting 3 from y C. Nothing, the correct import is java.util for the Point class D. Nothing, the correct import is java.awt for the Point class E. None of the Above

D

What does the ifEmpty() method return when a set's size is zero? A. 0 B. false C. 1 D. true E. None of the Above.

D

What is Boxing? A. The transfer of an Object from one class to another B. An automatic conversion from a wrapped object to its corresponding primitive data C. The transfer of one class to another D. An automatic conversion from primitive data to a wrapped object of the appropriate type E. An automatic conversion from primitive objects to a wrapped object of the appropriate type

D

What is a Collection? A. An array that stores a group of user-inputted variables, called its elements B. An array that stores a group of objects, called its elements C. An object that stores a group of user-inputted variables, called its elements D. An object that stores a group of other objects, called its elements E. None of the Above

D

What is a set? A. A collection that is comprised of only strings. B. A collection that is comprised of only doubles or integers. C. A collection that can contain duplicates. D. A collection that cannot contain duplicates. E. None of the above.

D

What is an Implicit Parameter? A. A set of values (internal data) stored in an object. B. A variable outside of an object that makes up part of its external state. C. An instance method that modifies the object's internal state. D. The object that is referenced during an instance method call. E. None of these definitions.

D

What is an object that allows the efficient retrieval of the elements of a list in sequential order? A. order B. sequence C. count D. iterator E. None of the above.

D

What is an object that stores a group of other objects, called its elements? A. Object B. Source C. List D. Collections E. None of the above.

D

What is a weakness of using a "Set"? A. Slow to search B. Not a general-purpose collection C. Slow to add/remove arbitrary elements D. Unable to easily map backward from a value E. None of the Above

E

What is the output of the following code? HashMap<Integer, Character> set = new HashMap<>(); set.put(3, 97); System.out.println(set.values());; A. Error, because you cannot have two semicolons at the end of a statement. B. Error, because the first "HashMap" should be "Map" instead. C. Error, because the second "HashMap" should be "Map" instead. D. Error, because 97 cannot be converted to Character. E. No errors and prints [a].

D

What is writing a new version of a method in a subclass that replaces the superclass's version? A. dynamic binding. B. inheritance. C. is-a relationship. D. override. E. None of the above

D

What will this piece of code print? Point p = new Point(); p.x = 10; p.y = 7; System.out.println("p is " + p); A. p is (10,7) B. p is 10,7 C. p is coordinates(10,7) D. p is Point@9e8c34 E. None of the above.

D

When using a set, what is one thing you cannot do. A. Set values to 0. B. Examine data. C. Alphabetize data. D. Duplicate data. E. All of the above.

D

Which is false about a module? A. It is a partial program. B. It does not have a main. C. It is meant to be utilized by other client classes. D. It is a complete program. E. It is not run directly.

D

Which of the following is a private method of the object class? A. toString() B. hashCode() C. getClass() D. clone() E. equals(obj)

D

Which of the following methods of the object class creates a copy of the object? A. copy() B. make() C. create() D. clone() E. None of the above

D

Which of the following would not cause an error? A. Set<Point> set = new TreeSet<>(); set.add(new Point(1,2)); B. Set<Integer> set = new Treeset<>(); set.add(1); C. TreeSet<Integer> set = new TreeSet<>(); set.add(1.2); D. TreeSet<Integer> set = new TreeSet<>(); set.add(1); E. All of the above would produce errors.

D

Which two operations are common to all shapes? A. perimeter, volume B. area, volume C. height, weight D. perimeter, area E. length, width

D

A class is a program entity that can represent _______. A. A programming language. B. A program / module. C. An importable function. D. A template for a new type of objects. E. Both B and D.

E

How many objects can a polymorphic code be used in? A. 0 B. 1 C. 2 D. 3 E. Infinite

E

If ArrayList<String> numbers = new ArrayList<>(); then what would you use to print it? A. System.out.print(ArrayList<String> numbers); B. System.out.print(String numbers); C. System.out.print(a[s] numbers); D. System.out.print(list numbers); E. System.out.print(numbers);

E

What happens when you try to modify the list created by List<Integer>nums = List.of(10,20,30,40); ? A. Your program will crash. B. You can modify will no problems. C. You will get a java.lang.UnsupportedOperationException thrown. D. You can add or remove an integer at any time. E. Both A and C.

E


Related study sets

Wongs Ch 6. Childhood Communicable and Infectious Disease

View Set

International Business: Module 9

View Set

Chapter 05: Pain Assessment and Management in Children Hockenberry: Wong's Essentials of Pediatric Nursing, 10th Edition

View Set