Programming Exam 2
In OOP The ability to send the same message to distinct object and having different behaviours better describes the concept of: A) Polymorphism B) Encapsulation C) Composition D) Inheritance
Polymorphism
In the catch block below, what is e? catch (ArithmeticException e) { System.err.printf(e); } A) The type of the exception being caught. B) The name of catch block's exception parameter. C) A finally block. D) An exception handler.
The name of the catch block's exception parameter
If a method is declared static in a particular class, what does that mean? A) The method cannot modify any variables B) It can only be called from within the class C) You need an instance of the class to access it, even though it can't access instance variables/methods D) You do not need an instance of the class to access it, because it can't access instance variables/methods
You do not need an instance of the class to access it, because it can't access instance variables/methods
To establish a connection you must specify: a. Port b. Speed of Connection c. IP Address or name of Server d. Network Protocol
A AND C
Which statement is false? A) Classes are reusable software components B) A class is to an object as a blueprint is to a house. C) Performing a task in a program requires a method D) A class is an instance of its object
A class is an instance of its object. *The reverse it true*
Given the following definitions which assignments are legal? class Box{} class SuperBox extends Bod{} A) Box b = new Box(); B) Box b = new SuperBox(); C) Box b = SuperBox();
Box b = new SuperBox()
Arrays are ______. A) Variable-length entities B) Fixed-length entities C) Data structures that contain up to 10 related data items. D) Used to draw a sequence of lines, or "rays"
Fixed-Length Entities
Which of the following is false? A) Classes (and their objects) encapsulate, i.e., encase, their attributes and methods. B) A class's (and its object's) attributes and methods are intimately related. C) For objects to communicate effectively with one another, each must know how the other object is implemented D) Information hiding is crucial to good software engineering.
For objects to communicate effectively with one another, each must know how the other object is implemented.
_________ Enable programmers to specify, with a single method declaration, a set of related methods. A) Overloaded methods B) Overriden methods C) Generic methods D) Generics
Generic Methods
__________ enable programmers to specify, with a single method declaration, a set of related methods. a. Overloaded methods. b. Overriden methods. c. Generic methods. d. Generics.
Generic Methods
Which of the following is not a valid identifier: A) my Value B) $_AAA1 C) width D) m_x
my Value
Which of the following is not possible: A) A class that implements two interfaces B) A class that inherits from two classes C) A class that inherits from one class, and implements an interface D) All of the above are possible
A class that inherits from two classes.
Which statement is false? A) A list is a collection B) A list cannot contain duplicate elements. C) A list is sometimes called a sequence. D) Lists use zero-based indices.
A list cannot contain duplicate elements.
Which of the following statements is true? a. Overloaded methods are often used to perform similar operations on different types of data. b. When the compiler encounters a method call, it attempts to locate a method declaration with a name and parameters that are compatible with the argument types in the method call. c. Both a) and b) are true. d. Neither a) nor b) is true.
Both a) and b) are true.
Which of the following statements is false: A) HashSet and TreeSet are allowed to store only unique elements in their objects. B) Duplicate elements can exist inside the HashSet and TreeSet objects. C) HashSet stores the elements in random order. D) TreeSet stores the elements in ascending order.
Duplicate elements can exist inside the HashSet and TreeSet objects.
If no elements are in the stack, method pop throws an ____. A) OutOfMemoryError. B) OutOfMemoryException C) EmptyStackError. D) EmptyStackException.
EmptyStackException
Polymorphism allows for specifics to be deals with during: A) Execution B) Compilation C) Programming D) Debugging
Execution
It's recommended that you do not explicitly create and use Thread objects to implement concurrency, but rather use the ________ interface. a. ExecutorService b. Runnable c. Concurrent d. Executor
Executor
Class _____ represents an image that can be displayed on a JLabel A) Image B) Icon C) ImageIcon D) IconImage
ImageIcon
Which keyword is used to specify that a class will define the methods of an interface: A) Uses B) Implements C) Defines D) Extends
Implements
Which of the following statements is false about interfaces. A) An interface is a variation of the idea of an abstract class B) All non-static and non-default methods declared in an interface are implicitly public abstract methods. C) In an interface, all methods are non-abstract. D) It is possible to call methods of the interface on any object of a class that implements mechanic.
In an interface all methods are non-abstract
A new class of objects can be created conveniently by _____; the new class (called the ______) starts with the characteristics of an existing class (called the _______) , possibly customizing them and adding unique characteristics of its own. A) inheritance, superclass, sublclass B) composition, subclass, superclass C) inheritance, subclass, superclass D) composition, superclass, subclass.
Inheritance, subclass, superclass.
Java supports _____; collections of related methods that typically enable you to tell objects what to do, but not how to do it (we'll see an exception to this in Java SE 8) A) classes B) subclasses C) superclasses D) interfaces
Interfaces
Declaring a class final means: A) It will prepare the object for garbage collection. B) It cannot be accessed from outside its class C) It cannot be extended D) It cannot be abstract
It cannot be extended
If a variable is declared static in a particular class what does that mean? A) It cannot be changed B) It can only be changed by the instances of the class in which it is declared C) There is only 1 copy of it that all instances of the class can access D) Each instance of the class has its own copy of the variable
There is only 1 copy of it that all instances of the class can access
If a variable is declared static in a particular class what does that mean? A) It cannot be changed B) It can only be changed by the instances of the class in which it is declared C) There is only 1 copy of it that all instances of the class can access D) Each instance of the class has its own copy of the variable
There is only one cop of it that all instances of the class can access
In the interface professional there is the following code: public abstract String getSkills(); In this case, which of the following statements is true? A) It is not necessary to implement this method because this is a concrete method. B) This method can be accessed without instantiating an object of the interface. You just need to use the name of the interface and a dot(.) separator: Professional.getSkills(); C) this method should be implemented as final by any class. D) This is an abstract method and it should be implemented in the class that implements the insterface; otherwise, this class must be declared as abstract as well.
This is an abstract method and it should be implemented in the class that implements the interface; otherwise, this class must be declared as abstract as well.
Each class you create becomes a new ____ that can be used to declare variables and create objects A) Package B) Instance C) Library D) Type
Type
If no exceptions are thrown in a try block, where does control proceed to when the try block completes execution. A) This will result in a compiler error, one of the exceptions must be thrown. B) The first catch block will execute and the program will terminate C) The catch blocks for that try statement are skipped, and the program resumes execution after the last catch block. D) The code will pass control to the parents (super class) exception handler
The catch blocks for that try statement are skipped and the program resumes execution after the last catch block
Which statement is false: A) The compiler always creates a default constructor for a class. B) If a class's constructors all require arguments and a program attempts to call a no-argument constructor to initialize an object of the class, a compilation error occurs. C) A constructor can be called with no arguments only if the class does not have any constructors or if the class has a public no-argument constructor D) None of the above
The compiler always creates a default constructor for a class
If a method is declared static in a particular class, what does that mean? A) The method cannot modify any variables B) It can only be called from within the class C) You need an instance of the class to access it, even though it cant access instance variables/methods D) You dont need an instance of the class to access it, because it cant access instance variables/methods
You dont need an instance of the class to access it, because it cant access instance variables/methods
All generic method declarations have a type parameter section delimited by __________. a. curly brackets ({ and }). b. angle brackets (< and >). c. square brackets ([ and ] ). d. parenthesis
angle brackets (< and >).
Which of the following is not a valid Java Identifier? A) myClemsonTigers B) $_Money C) carname_for_my_old_mazda_rx7 D) e=mc2
e=mc2
What is T in the following class declaration? public class Array<T> { }
in class
Two tasks that are operating ________ are executing simultaneously. a. concurrently b. in parallel c. sequentially d. iteratively
in parallel
Which of the following could be used to declare abstract method method1 in abstract class Class1 (method1 returns an int and takes no arguments)? a. public int method1(); b. public int abstract method1(); c. public abstract int method1(); d. public int nonfinal method1();
public abstract int method1();
Method _____ Can be used to set the layout manager of a container A) setManager B) setLayout C) setLayoutManager D) setGUILayout
setLayout
The classes and interfaces which comprise the collections framework are members of package ______. A) .java.util. B) .javax.swing. C) .java.collections. D) .java.collection.
.java.util.
In an interface, all fields are implicitly public, static and final. In the interface Professional there is the following code: public static final String strMessage = "Message" In this case which of the following statements is true: A) strMessage is not a constant and can be accessed and changed via the name of the interface and a dot(.) separator: Professional.strMessage B) strMessage is a constant and can be accessed only via a reference to an object of the interface. C) strMessage is a constant and can be accessed via the name of the interface and a dot(.) separator: Professional.strMessage. D) strMessage is not a constant and can be accessed and changed only via a reference to an object of the interface.
strMessage is a constant and can be accessed via the name of the interface and a dot(.) separator: Professional.strMessage.
Both abstract classes and interfaces allow you to declare method signatures and provide no implementation of such methods. Why then might you use an abstract class as opposed to an interface? A) There's no good reason why, they're basically the same. B) If you have an abstract class A you can create an instance of it like so: A var = new A(); but you wouldnt be able to do this with an interface. C) Abstarct classes can define functionality and non-constant fields that subclasses can use, while requiring subclasses to provide their own implementations for certain operations. D) You wouldn't because abstract classes are only used in special situations where you want to prevent inheritance, since they cannot be inherited from, but you can inherit from interfaces.
Abstarct classes can define functionality and non-constant fields that subclasses can use, while requiring subclasses to provide their own implementations for certain operations.
A class that does not implement all methods of the interface is a class that cannot be instantiated and must be declared. A) Abstract B) Final C) Static D) Concrete
Abstract
A(n) _____ Class cannot be instantiated. A) Final B) Concrete C) Abstract D) Polymorphic
Abstract
Which of the following statements is false about abstract classes: A) An abstract class is a class which declares the existence of some methods but not its implementation B) Abstract classes are used to represent some fundamental behavior expected for all specialized classes C) All non implemented methods of an abstract class should be implemented in its subclasses D) Abstract classes are complete classes that can be used to instantiate objects.
Abstract classes are complete classes that can be used to instantiate objects.
Which of the following statements about abstract super-classes is true? A) Abstract superclasses may contain data. B) Abstract superclasses may not contain implementations of methods. C) Abstract superclasses must declare all methods as abstract. D) Abstract superclasses must declare all data members not given values as abstract.
Abstract superclasses may contain data.
When the user presses 'enter' in a JPasswordField, the GUI component generates an ____, which is processed by an object that implements the interface ____. A) ActionEvent, ActionListener. B) ActionEvent, ActionEventListener. C) TextEvent, TextListener. D) TextEvent, TextEventListener.
ActionEvent,ActionListener
All generic method declarations have a type parameter section delimited by ______. A) Curly brackets ({and}) B) Angle brackets (<and>) C) Square brackets ([and]) D) Parenthesis
Angle Brackets (<and>)
Which of the following does not complete the sentence correctly? An interface ______. A) Forces classes that implement it to declare all the abstract interface methods B) Can be used in place of an abstract class when there is no default implementation to inherit. C) Is declared in a file by itself and is saved in a file with the same name as the interface followed by the .java extension. D) Can be instantiated.
Can be instantiated
Which statement is false? A) A ListIterator accesses the elements of a List. B) Class ArrayList is a fixed-size array. C) A LinkedList is a linked list implementation of a list D) ArrayLists execute faster than Vectors because they are not thread safe.
Class ArrayList is a fixed-size array.
Many of Java's networking classes are contained in package .
Java.net
.ClassCollections provides algorithms for reversing, filling and copying _____. A) Lists B) Collections C) Arrays D) Stacks
Lists
When a method terminates, the values of its local variables are ______. A) Saved B) Copied C) Restored D) Lost
Lost
In a class containing methods with the same name, the methods are distinguished by
Number and/or types of parameters NOT return type
Maps allocate keys to values and cannot contain duplicate keys, the key-to-key value mapping is a _______ mapping. A) Many-to-Many B) Many-to-One C) One-to-Many D) One-to-One
One-to-One
Overriding a method differs from overloading a method because: A) Overloaded methods have the same signature B) Overridden methods have the same signature C) Both of the above D) Neither of the above
Overridden methods have the same signature.
Stack method _______ looks at the top element of a stack without removing the element. A) Push B) Peek C) Look D) Up
Peek
The preferred means of creating multithreaded Java applications is by implementing the ________ interface. An object of a class that implements this interface represents a task to perform. a. Thread b. Runner c. Runnable d. None of the above.
Runnable
The collections framework provides various _____ collection interfaces from which the programmer can quickly "Flesh Out" Complete customized implementations A) Abstract B) Concrete C) Structured D) Unstructured
Structured
When a __________ method or block is running on an object, the object is locked so no other such method can run on that object at the same time. a. synchronized b. shared c. thread d. writeable
Synchronized
