c

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Mutator methods typically take

one parameter, of the same type as the corresponding field.

What is the output of this code sequence? int [ ] a = new int[10]; for ( int i = 0; i < a.length; i++ ) a[i] = i + 10; System.out.println( a[4] );

14

What is the output of this code sequence? double [ ] a = { 12.5, 48.3, 65.0 }; System.out.println( a.length );

3

What is the value of i after this code sequence is executed? int i = 0; for ( i = 0; i <= 2; i++ ) System.out.println( "Hello" );

3

What is printed when this code sequence is executed? for ( int i = 0; i < 5; i++ ) { System.out.print( Math.max( i, 3 ) + " " ); }

3 3 3 4

What is the output of this code sequence? int [ ] a = { 12, 48, 65 }; int i = 1; System.out.println( "a[" + i + "] = " + a[i] );

a[1] = 48

How do you access the 6th element?

a[5]

In a class, fields...

can be basic data types, existing Java types, or user-defined types (from user-defined classes).

What are the values of i and sum after this code sequence is executed? int sum = 0; int i = 17; while ( i % 10 != 0 ) { sum += i; i++; }

i = 20, sum = 54

What are the values of i and sum after this code sequence is executed? int i = 0; int sum = 0; for ( i = 0; i < 40; i++ ) { if ( i % 10 == 0 ) sum += i; }

i = 39, sum = 30

What are the values of i and sum after this code sequence is executed? int i = 0; int sum = 0; for ( i = 0; i < 5; i++ ) { sum += i; }

i = 4, sum = 10

In a class, if a field is private

it can be accessed directly only from inside its class.

Accessor methods typically take

no parameter.

What is the output of this code sequence? int s = 0; int [ ] a = { 12, 48, 65 }; for ( int i = 0; i < a.length; i++ ) s += a[i]; System.out.println( "s = " + s );

s = 125

What is the value of sum after this code sequence is executed? int sum = 0; for ( int i = 0; i <= 10; i += 2 ) { sum += i; }

sum = 20

What is the value of sum after this code sequence is executed? int sum = 0; for ( int i = 10; i > 5; i-- ) { sum += i; }

sum = 40

When coding a method that performs calculations on fields of that class,

these fields do not need to be passed as parameters to the methods because the class methods have direct access to them.

You can simulate a for loop with a while loop.

true

Accessors and mutators are.

used to access and modify field variables of a class from outside the class.

What is the output of this code sequence? (The user successively enters 3, 5, and -1.)

Hi Hi

What is the output of this code sequence? (The user successively enters 3, 5, and -1.) int i = 0; while ( i != -1 ) { System.out.print( "Hi " ); i = scan.nextInt( ); }

Hi Hi Hi

What is the default value for a newly instantiated array of ints?

0

What is the first index of an array?

0

What is the output of this code sequence? int [ ] a = new int [6]; System.out.println( a[4] );

0

What is the value of i after this code sequence is executed? int i = 0; for ( i = 0; i < 2034; i++ ) System.out.println( "Hello" );

0

What is the output of this code sequence? for ( int i = 0; i < 3; i++ ) System.out.print( i ); System.out.print( " Done" );

0 1 2 Done

What is the output of this code sequence? for ( int i = 0; i <= 2; i++ ) System.out.print( i ); System.out.print( " Done" );

0 1 2 Done

What is the output of this code sequence? int [ ] a = { 12, 48, 65, 23 }; int temp = a[1]; a[1] = a[3]; a[3] = temp; for ( int i = 0; i < a.length; i++ ) System.out.print( a[i] + " " );

12 23 65 48

What is the output of this code sequence? double [ ] a = { 12.5, 48.3, 65.0 }; System.out.println( a[1] );

48.3

What is the output of this code sequence? double [ ] a = { 12.3, 99.6, 48.2, 65.8 }; double temp = a[0]; for ( int i = 1; i < a.length; i++ ) { if ( a[i] > temp ) temp = a[i]; } System.out.println( temp );

99.6

What is a constructor's return type?

A constructor does not have a return type.

In a typical class, what is the general recommendation for access modifiers?

Instance variables are private and methods are public.

How do you discover that you have an infinite loop in your code?

The code compiles but runs forever.

If you want to execute a loop body at least once, what type of loop would you use?

do/while

Members of the class are

fields and methods


Ensembles d'études connexes

Chapter Quizzes (found at the end of chapter 11 & 12)

View Set

Human Nutrition Exam Review (ch 5-7)

View Set

314: Exam 4 (Chapter 44, 46, 47)

View Set

Chapter/Quiz 9: Lifespan Development

View Set

Financial Management Quiz Review

View Set

Openstax Introduction to Sociology Chapter 1

View Set

2. BUS 110 Intro to Business Ch 5 Summary

View Set

Economics - Unit 1: What Is Money

View Set

a&p chapter 8: skeletal system- axial and appendicular skeleton

View Set

Unit 5: Applying Transitions & Animations

View Set