CSE 110 Exam 2 Quiz 7

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

The behavior of an object is defined by the object's

instance data

Use the following class definition: public class Swapper { private int x; private String y; public int z; public Swapper(int a, String b, int c) { x = a; y = b; z = c; } public String swap( ) { int temp = x; x = z; z = temp; return y; } public String toString( ) { if (x < z) return y; else return "" + x + z; } } If the instruction Swapper s = new Swapper(0, "hello", 0); is executed followed by s.toString( ); what value is returned from s.toString( )?

"00"

Use the following class definition: public class Swapper { private int x; private String y; public int z; public Swapper(int a, String b, int c) { x = a; y = b; z = c; } public String swap( ) { int temp = x; x = z; z = temp; return y; } public String toString( ) { if (x < z) return y; else return "" + x + z; } } If we have Swapper r = new Swapper (5, "no", 10); then r.swap( ); returns which of the following?

"no"

What is a mutator method?

A method that modifies a value

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

False

Assume that boolean done = false, int x = 10, int y = 11, String s = "Help" and String t = "Goodbye". The expression (s.concat(t).length( ) < y) is true.

False

Use the following class definition: public class Swapper { private int x; private String y; public int z; public Swapper(int a, String b, int c) { x = a; y = b; z = c; } public String swap( ) { int temp = x; x = z; z = temp; return y; } public String toString( ) { if (x < z) return y; else return "" + x + z; } } Which of the following criticisms is valid about the Swapper class?

The instance data z is visible outside of Swapper

A constructor must have the same name as its class.

True

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

What is the return type of a method that does not returns any value?

void


Set pelajaran terkait

Lesson 1. Using Few Words or Being Quiet (brevity, concise, laconic, pithy, quiescent, reticent, succinct, taciturn, terse)

View Set

Chapter 5 - Smartbook Assignment

View Set

Business Chapter 2: Business Ethics & Social Responsibility

View Set

Taylor Chapter 24 Vital Signs Prep U

View Set

SCM 421 Topic 1: Purchasing & Supply Management

View Set

Simple Interest and Compound Interest

View Set

Molecular biology week 3A - Nucleic acid chemistry

View Set