Quiz 1 Data Structure

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

The combination of data together with its methods is called a(n) ________ Data type.

Abstract

(True/False) An interface is a class

False

The call to _____ invokes the constructor for the current class whose parameter list matches the argument list. (a) super (b) super() (c) this() (d) abstract

this()

(True/False) Each class that implements an interface must provide the complete definition of all methods declared in the interface.

True

What is the difference between a local variable and a field?

A local variable is declared in the body of a method and can be used only from the point at which it's declared through the end of the method declaration. A field is declared in a class, but not in the body of any of the class's methods. Also, fields are accessible to all methods of the class (with one exception: static fields are not accessible to non-static methods).

Which of the following statements is correct? (a) Abstract classes can define constants. (b) Interfaces can extend another class. (c) Instances of abstract classes can be created.

Abstract classes can define constants

A(n) _____________ is a model of a physical entity or activity. (a) abstraction (b) interface (c) contract (d) use case

Abstraction

A Java interface is a(n) ___________ between the interface designer and the programmer who codes a class that implements the interface. (a) precondition (b) postcondition (c) message (d) contract

D

Method descriptions in an interface are called method ____________

Declaration

(True/False) The has-a relationship between classes means that one class is a subclass of the other.

False

(True/False) The is-a relationship between classes means that one class has the second class as an attribute.

False

(True/False) An array can store many different types of values.

False. An array can store only values of the same type.

Which of the following statements is correct? (a) is-a and has-a relationships cannot be combined. (b) An abstract class can be instantiated. (c) An abstract class cannot declare abstract methods. (d) In Java, a variable of a superclass type can reference an object of a subclass type.

In Java, a variable of a superclass type can reference an object of a subclass type.

The nextInt() method will throw a(n) ______ if an integer choice is not entered.

InputMismatchException

A Java ___________ specifies the names, parameters, and return values of the ADT methods without specifying how the methods perform their operations or how the data is internally represented.

Interface

The The nextInt() method will throw a(n) _________ is thrown when a program attempts to convert a non-numeric string to a numeric value.

NumberFormatException

The superclass of all Java classes is _________

Object

_____ errors occur during program execution .

Runtime

(True/False) A major reason for the popularity of object-oriented programming is that it enables programmers to reuse previously written code saved as classes.

True

Which of the following methods of java.lang.Object compares an object to its argument? (a) boolean equals(Object obj) (b) int hashCode() (c) Object clone() (d) String toString()

boolean equals(Object obj)

A Java interface is a(n) _____________ between the interface designer and the programmer who codes a class that implements the interface. (a) precondition (b) postcondition (c) message (d) contract

contract

Which of the following would cause an ArrayIndexOutOfBounds error? (a) public boolean setElementOfX(int index, int val) { if (index >= 0 && index < x.length) { x[index] = val; return true; } else { return false; } } (b) public static void main(String[] args) { String inputFileName; if (args.length > 0) inputFileName = args[0]; else inputFileName = "Phone.dat"; } (c) for (int i = 0; i < x.length; i++) x[i] = i + i; (d) for (int i = 0; i <= x.length; i++) x[i] = i * i;

d

If a class declares constructors, the compiler will not create a(n) ________.

default constructor

One way to make code reusable is to ___________ or combine data elements together with methods that operate on that data in a separate program module.

encapsulate

Having multiple methods with the same name but different signatures in a class is called _______

method overloading

It's possible to have several methods with the same name that each operate on different types or numbers of arguments. This feature is called method ______________________.

method overloading

Keyword ________ requests memory from the system to store an object, then calls the corresponding class's constructor to initialize the object.

new

If no constructors are defined for a class, the _____ constructor for that class will be provided by default. (a) private (b) super (c) public (d) no-parameter

no-parameter

Which of the following is considered a visibility modifier in Java? (a) private (b) Inherit (c) superclass (d) String

private

_______________ visibility is for members of a class that should not be accessible to anyone but the class, not even classes that extend it.

private

A data field (or method) with ____ visibility can be accessed in either the class defining it, in any subclass of that class, or any class in the same package. (a) private (b) protected (c) public (d) instanceof

protected

Classes that are not part of a package may access only _______ members of classes in the package

public

The public methods of a class are also known as the class's __________

public interface

If a method contains a local variable with the same name as one of its class's fields, the local variable _________ the field in that method's scope.

shadows

A(n) _______ variable represents classwide information that's shared by all the objects of the class.

static

You should always override the _______ method if you want to represent an object's state.

toString

Java automatically applies the _________ method to an object referenced in a String expression

toString()

A(n) _________ class is used to store a primitive-type value in an object type.

wrapper


Set pelajaran terkait

Health care systems exam 2 questions

View Set

PKN 2 / BAB 2 : RINGKASAN MATERI 2 1

View Set

PSYC10004 Developmental Psychology

View Set

Keyboard Shortcuts for Word 2016

View Set

V.B: INV. ANALYSIS, REC & ACTION - Communications with Clients and Prospective Clients

View Set

Thermodynamics Reading Quizzes (#2)

View Set