Java Chp 4

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

To define a class that will represent a car, which of the following definitions is most appropriate?

public class Car

A class' constructor usually defines

how an object is initialized

If a method does not have a return statement, then

it must be a void method

Instance data for a Java class

may be primitive types or objects, but objects must be defined to be private

Which of the following reserved words in Java is used to create an instance of a class?

new

The relationship between a class and an object is best described as

objects are instances of classes

If the instruction Swapper s = new Swapper(0, "hello", 0); is executed followed by s.toString( ); what value is returned from s.toString( )?

"00"

If we have Swapper r = new Swapper (5, "no", 10); then r.swap( ); returns which of the following?

"no"

A class's instance data are the variables declared in the main method

False

A constructor must always return an int

False

Formal parameters are those that appear in the method call and actual parameters are those that appear in the method header.

False

Java methods can return only primitive types (int, double, boolean, etc)

False

What part of a class is described as the state

Instance Variable

In order to preserve encapsulation of an object, we would do all of the following except for which one?

Make the class final

What part of the class is described as the behavior

Methods

Which of the following criticisms is valid about the Swapper class?

The instance data z is visible outside of Swapper

A constructor is a method that gets called automatically whenever an object is created, for example with the new operator.

True

The number and types of the actual parameters must match the number and types of the formal parameters.

True

While multiple objects of the same class can exist, there is only one version of the class.

True

Consider a method defined with the header: public void doublefoo(double x). Which of the following method calls is legal?

all of the above are legal except for d

Private

an access modifier used for attributes, methods and constructors, making them only accessible within the declared class

Public

declares a member's access as public

Consider a method defined with the header: public void foo(int a, int b). Which of the following method calls is legal?

foo(0 / 1, 2 * 3);

Void

should not have a return value

Static

the particular member belongs to a type itself, rather than to an instance of that type


Kaugnay na mga set ng pag-aaral

Factoring Polynomials: Difference of Squares

View Set

Champions A Set 5 Example Sentences

View Set

What are the main advantages and disadvantages of experiments?

View Set

ECO2013 Chapter 16 Monetary System

View Set

Comparative Politics Exam 1 Nunes

View Set