Programming 2 Final

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

b. The name of catch block's exception parameter.

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.

all of the above

The parameter list in the method header and the arguments in the method call must agree in: number type order all of the above

This porridge is too hot. This porridge is just right!

What is output by the following Java code segment? int temp = 180; if (temp > 90) { System.out.println("This porridge is too hot."); // cool down temp = temp - (temp > 150 ? 100 : 20); } else { if (temp < 70) { System.out.println("This porridge is too cold."); // warm up temp = temp + (temp < 50 ? 30 : 20); } } if (temp == 80) System.out.println("This porridge is just right!");

lost

When a method terminates, the values of its local variables are ________.

a. abstract superclasses may contain data.

Which of the following statements about abstract superclasses 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.

b. A List cannot contain duplicate elements.

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.

b. Class ArrayList is a fixed-size array.

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.

d. A class is an instance of its object. The reverse is true.

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.

c. 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.

private

Declaring instance variables ________ is known as data hiding or information hiding.

type

Each class you create becomes a new ________ that can be used to declare variables and create objects.

a. False - they can have the same name, and thay can overload other generic methods

T/F a. A generic method cannot have the same method name as a nogeneric method

inheritance, subclass, superclass

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.

Abstract classes can define functionality and non-constant fields that subclasses can use, while requiring subclasses to provide their own implementations for certain operations, whereas interfaces just define method signatures (and return types) and constants

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?

II. Box b = new SuperBox(); Only

Given the following definitions, which assignments are legal? class Box{} class SuperBox extends Box{} I. Box b = new Box(); II. Box b = new SuperBox(); III Box b = new SuperBox()

zero

How many times is the body of the loop below executed? int counter = 1; while (counter < 20) { // loop body counter = counter +2; }

D. You do not need an instance of the class to access it, because it can't access instance variables/methods

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

D. You do not need an instance of the class to access it, because it can't access instance variables/methods

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

C. 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

C. 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

Number and/or types of parameters NOT return type

In a class containing methods with the same name, the methods are distinguished by?

d. Executor

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

c. Runnable

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.

Port and IP Address or name of Server

To establish a connection you must specify: a. Port b. Speed of Connection c. IP Address or name of Server d. Network Protocol

b. in parallel

Two tasks that are operating ________ are executing simultaneously. a. concurrently b. in parallel c. sequentially d. iteratively

ignored

What happens when an exception is thrown, but the try statement does not have a catch clause that is capable of catching it?

parameter

What is T in the following class declaration? public class Array<T> { }

Port

What is a connection point or interface between a computer and an external or internal device.

Socket

What is a one endpoint of a two-way communication link between two programs running on the network.

IP Address

What is a unique string of numbers separated by periods that identifies each computer using the Internet Protocol to communicate over a network.

a. synchronized

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

ActionEvent, ActionListener.

When the user presses Enter in a JPasswordField, the GUI component generates an , which is processed by an object that implements the interface .

++arrayName[i]

Which expression adds 1 to the element of array arrayName at index i? ++arrayName[i]. arrayName++[i]. arrayName[i++]. None of the above.

my Value

Which is not a valid Java identifier?

c. public abstract int method1();

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();

e=mc2

Which of the following is not a valid Java identifier? myClemsonTigers $_Money carname_for_my_old_mazda_rx7 e=mc2

c. For objects to communicate effectively with one another, each must know how the other object is implemented. Actually, Objects are normally not allowed to know how other objects are implemented—implementation details are hidden within the objects themselves.

Which of the following statements 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.

c. Both a) and b) are true. Overloaded methods are often used to perform similar operations on different types of data. 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.

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.

b. False - All generic method declarations have a type-parameter section immediately preceding the method's return type: public static <K, V> boolean compare(Pair<K, V> p1, Pair<K, V> p2) { return p1.getKey().equals(p2.getKey()) && p1.getValue().equals(p2.getValue()); }

T/F b. All generic method declarations have a type-parameter section that immediately precedes the method name

True

T/F c. The scope of a generic class's type parameter is the entire class, except its static members

The compiler always creates a default constructor for a class.

Which statement is false? The compiler always creates a default constructor for a class. 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. 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. None of the above.

c. 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.

angle brackets (< and >).

All generic method declarations have a type parameter section delimited by __________.

b. angle brackets (< and >).

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.

b. fixed-length entities

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"

ImageIcon

Class ________ represents an image that can be displayed on a JLabel.

4) Both (a) and (b) 1) Must implement a method called calculate. 2) Will not be able to access the instance variable a.

Consider the abstract superclass below: public abstract class Foo { private int a; public int b; public Foo(int aVal, int bVal) { a = aVal; b = bVal; } public abstract int calculate(); } Any concrete subclass that extends class Foo: 1) Must implement a method called calculate. 2) Will not be able to access the instance variable a. 3) Neither (a) nor (b). 4) Both (a) and (b).

Link Layer- involves the actual hardware used to communicate with nearby physically connected hosts. The link layer transports raw packets from one host to another on the same physical network. IP Layer- provides packet transport from one host to another in such a way that the packets can pass across multiple physical networks. Transport Layer- provide basic data transport from one host to another, much like IP, but add the notion of port numbers. These port numbers let you run multiple services on a single host by providing a way to tell the receiving host which service should receive that particular message. Application Layer- sits at the top of the protocol stack. This layer includes such protocols as hypertext transfer protocol (HTTP) and file transfer protocol (FTP).

Java provides a protocol at the transport layer of the Network Stack. We discuss the network stack - specifically TCP/IP and UDP Please describe these protocols

Interfaces

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).

java.net

Many of Java's networking classes are contained in package .

setLayout

Method can be used to set the layout manager of a container.

Overridden methods have the same signature.

Overriding a method differs from overloading a method because: Overloaded methods have the same signature. Overridden methods have the same signature. Both of the above. Neither of the above.

False; packets can be lost, arrive out of order or be duplicated.

State whether each of the following is true or false. d) Datagram packet transmission over a network is reliable—packets are guaranteed to arrive in sequence.

False; UDP is a connectionless protocol and TCP is a connection-oriented protocol.

State whether each of the following is true or false. a) UDP is a connection-oriented protocol.

True

State whether each of the following is true or false. c) A server waits at a port for connections from a client.

True

State whether each of the following is true or false.b) With stream sockets a process establishes a connection to another process.

I. p = ug; II. p = new Undergraduate();

Suppose the class Undergraduate extends the class Student which extends the class Person. Given the following variable declaration: Person p = new Person(); Student s = new Student(); Undergraduate ug = new Undergraduate(); Which of the following assignments are legal? I. p = ug; II. p = new Undergraduate(); III. ug = new Student(); IV. ug = p; V. s = new Person();


Set pelajaran terkait

Essay 2: U Curve and W curve adjustment

View Set

Removal of Cases from State to Federal Court

View Set

Ch. 6 Exam - Health Insurance Policies: Health Insurance Policy Provisions

View Set

Financial Management Final Spring 18

View Set

cell bio in class practice questions exam 3

View Set

Chapter 11: Functional Organization of nervous tissue

View Set