ITP 120 Chapter 5 & 6

Ace your homework & exams now with Quizwiz!

Which symbol indicates that a member is public in a UML diagram?

+

Which symbol indicates that a member is private a UML diagram?

-

What will be returned from the following method?public static double methodA(){double a = 8.5 + 9.5;return a;}

18.0

When writing documentation comments for a method, you can provide a description of each parameter by using a ________.

@param tag

Local variables can be initialized with ________.

Any of these.

A value-returning method must specify ________ as its return type in the method header.

Any valid data type

If method A calls method B, and method B calls method C, and method C calls method D, when method D finishes, what happens?

Control is returned to method C.

________ refers to combining data and code into a single object.

Encapsulation

A method that gets a value from a class's field but does not change it is known as a mutator method.

False

In the method header the static method modifier means the method is available to code outside the class.

False

In the method header, the method modifier public means that the method belongs to the class, not a specific object.

False

Only constants and variables may be passed as arguments to methods.

False

The public access specifier for a field indicates that the field may not be accessed by statements outside the class.

False

The term "default constructor" is applied to the first constructor written by the author of the class.

False

When a local variable in an instance method has the same name as an instance field, the instance field hides the local variable.

False

Which of the following statements will create a reference, str, to the String "Hello, World"?

String str = "Hello, World";

Given the following code, what will be the value of finalAmount when it is displayed?public class Order{private int orderNum;private double orderAmount;private double orderDiscount;public Order(int orderNumber, double orderAmt,double orderDisc) { orderNum = orderNumber; orderAmount = orderAmt; orderDiscount = orderDisc;}public int getOrderAmount(){ return orderAmount;}public int getOrderDisc(){ return orderDisc;}}public class CustomerOrder{public static void main(String[] args){ int ordNum = 1234; double ordAmount = 580.00; double discountPer = .1; Order order; double finalAmount = order.getOrderAmount() -order.getOrderAmount() * order.getOrderDisc(); System.out.printf("Final order amount = $%,.2f\n",finalAmount);}}

There is no value because the object, order, has not been created.

A class is not an object. It is a description of an object.

True

A constructor is a method that is automatically called when an object is created.

True

A method that stores a value in a class's field or in some other way changes the value of a field is known as a mutator method.

True

A parameter variable's scope is the method in which the parameter is declared.

True

A value-returning method can return a reference to a non-primitive type.

True

An access specifier indicates how a class may be accessed.

True

Methods are commonly used to break a problem into small manageable pieces.

True

No statement outside the method in which a parameter variable is declared can access the parameter by its name.

True

Shadowing is the term used to describe where the field name is hidden by the name of a local or parameter variable.

True

The expression in a return statement can be any expression that has a value.

True

The java.lang package is automatically imported into all Java programs.

True

When an object is passed as an argument to a method, the object's address is passed into the method's parameter variable.

True

You must have a return statement in a value-returning method.

True

When a method tests an argument and returns a true or false value, it should return ________.

a boolean value

In a general sense, a method is ________.

a collection of statements that perform a specific task

If you attempt to use a local variable before it has been given a value, ________.

a compiler error will occur

What does the following UML diagram entry mean?+ setHeight(h : double) : void

a public method with a parameter of data type double that does not return a value

In the following code, System.out.println(num) is an example of ________.double num = 5.4;System.out.println(num);num = 0.0;

a void method

The following statement is an example of ________.import java.util.*;

a wildcard import statement

When an object, such as a String, is passed as an argument it is ________.

actually a reference to the object that is passed

The following statement is an example of ________.import java.util.Scanner;

an explicit import statement

All @param tags in a method's documentation must ________.

appear after the general description of the method

Values stored in local variables ________.

are lost between calls to the method in which they are declared

Values that are sent into a method are called ________.

arguments

A class's responsibilities include ________.

both of these

One or more objects may be created from a(n) ________.

class

A(n) ________ can be thought of as a blueprint that can be used to create a type of ________.

class, object

When an argument value is passed to a method, the receiving parameter variable is ________.

declared in the method header inside the parentheses

To create a method, you must write its ________.

definition

In a @return tag statement the description ________.

describes the return value

Given the following method header, which of these method calls is incorrect?public void displayValue(double x, int y);

displayValue(a, b); // where a is a short and b is a long

Given the following method header, which of these method calls is incorrect?public void displayValue(int x, int y);

displayValue(a, b); // where a is a short and b is a long

When you pass an argument to a method you should be sure that the argument's type is compatible with

e parameter variable's data type

It is common practice in object-oriented programming to make all of a class's ________.

fields private

A class specifies the ________ and ________ that a particular type of object has.

fields, methods

A constructor ________.

has the same name as the class

Overloading means that multiple methods in the same class ________.

have the same name but different parameter lists

Select all that apply. Any method that calls a method with a throws clause in its header must ________.

have the same throws clause and handle the potential exception

You should not define a class that is dependent on the values of other class fields ________.

in order to avoid having stale data

Another term for an object of a class is a(n) ________.

instance

When an object is created, the attributes associated with the object are called ________.

instance fields

Methods that operate on an object's fields are called ________.

instance methods

Assume that the following method header is for a method in class A.public void displayValue(int value)Assume that the following code segments appear in another method, also in class A. Which contains a legal call to the displayValue method?

int x = 7;displayValue(x);

When an argument is passed to a method ________.

its value is copied into the method's parameter variable

The ________ package is automatically imported into all Java programs.

java.lang

A method ________.

may have zero or more parameters

A ________ is a part of a method that contains a collection of statements that are performed when the method is executed.

method body

Class objects normally have ________ that perform useful operations on their data, but primitive variables do not.

methods

Most of the programming languages used today are ________.

object-oriented

The lifetime of a method's local variable is ________.

only while the method is executing

A group of related classes is called a(n) ________.

package

A special variable that holds a value being passed into a method is called a(n) ________.

parameter

In the header, the method name is always followed by ________.

parentheses

A constructor is a method that ________.

performs initialization or setup operations

When you work with a ________, you are using a storage location that holds a piece of data.

primitive variable

Which of the following is not a part of a method call?

return type

Which of the following is not part of a method header?

semicolon

Given the following method, which of these method calls is valid?public static void showProduct (int num1, double num2){int product;product = num1 * (int)num2;System.out.println("The product is " + product);}

showProduct(10, 4.5);

Instance methods do not have the ________ keyword in their headers.

static

Which of the following is not involved in identifying the classes to be used when developing an object-oriented application?

the code

The header of a value-returning method must specify ________.

the data type of the return value

The process of breaking a problem down into smaller pieces is sometimes called ________.

the divide and conquer method

The scope of a public instance field is ________.

the instance methods and methods outside the class

The scope of a private instance field is ________.

the instance methods of the same class

A parameter variable's scope is ________.

the method in which the parameter is declared

A UML diagram does not contain ________.

the object names

When an object is passed as an argument to a method, what is passed into the method's parameter variable?

the object's memory address

To indicate the data type of a variable in a UML diagram, you enter ________.

the variable name followed by a colon and the data type

Two or more methods in a class may have the same name as long as ________.

they have different parameter lists

Data hiding (which means that critical data stored inside the object is protected from code outside the object) is accomplished in Java by ________.

using the private access specifier on the class fields

A ________ type of method performs a task and then terminates.

void


Related study sets

The Boston Tea Party, Intolerable Acts & First Continental Congress

View Set

Alkenes and organic chemistry revision

View Set

MKT 320 Chapter 3 Guidepost questions

View Set

Chapter 2- Scanning Planes and Scanning Methods

View Set

Life and Health Insurance ExamFX

View Set

Intro to Business (Basic Vocab, Chapter 7)

View Set