Midterm Practice

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

A turtle object is at (1, 1). What does this.getOneIntersectingObject(Marker.class) return if no Marker object is at (1, 1)? It will return null. It will return an empty Marker object. It will return false. It will return 0.

It will return null.

Which of the following is true? Jeroo is a subclass of Harvester SkippingHarvester is a subclass of Harvester Harvester is a sublcass of PlantingHarvester PlantingHarvester is a subclass of SkippingHarvester

SkippingHarvester is a subclass of Harvester

Given the following Java boolean expression: !((a >= b) || (m < n)) Which of the following expressions is logically equivalent? (!(a < b) || !(m >= n)) !((a <= b) || !(m > n)) ((a <= b) && (m > n)) ((a < b) && (m >= n))

((a < b) && (m >= n))

What is the value of the variable z after the following code is executed? int w = 5; int x = 9; int y = 5; int z = 1; if (x % y >= w - z) { z--; if (y - 3 * w >= -x) { z++; } else { z--; } } else { z = 3; } -1 1 2 0 none of these 3

-1

What are the possible values of randomValue for the following statement: int randomValue = Random.generator().nextInt(26); 1 through 25 1 through 26 0 through 25 0 through 26

0 through 25

How many times does the following Java code print "hello world"? 0 1 6 none of the these. 4 10 5 7

7

Which of the following statements about constructors is NOT true? A class may have a constructor that takes no parameters. A constructor is called when a program creates an object with the new operator. A constructor must be declared with a return type of void. A constructor must have the same name as the class it is in. A constructor of a subclass can call a constructor of its superclass using the Java reserved word super.

A constructor must be declared with a return type of void.

**Note: This question deals with material from chapter 7.** What type of loop is the Java "while" loop? A pretest until loop. A posttest while loop. A posttest until loop. A pretest while loop.

A pretest while loop.

The simplified diagram above shows the relationships among classes Bird, Crow, and Duck. Suppose Russell is an instance of Crow and Howard is an instance of Duck. Which of the following statements is incorrect? Crow is an instance of Bird. Howard is an instance of Bird. Bird is the superclass of Duck. Russell has the capabilities and attributes of a Bird.

Crow is an instance of Bird. (A useful way to look at classes and instances is to use sets: a class describes a set of instances that share the same attributes and capabilities, and instantiating from a set produces a member of that set. From this perspective, a class's superclass is a superset of that class, defined by attributes and capabilities that are subsets of those of the class. So: all instances of a class are instances of all of its class's ancestors, and all instances of a class share the attributes and capabilities of that class. Thus Crow is not an instance of Bird.)

For any JUnit test class, when is the setUp() method executed? Only after the test class constructor method is executed. Each time before a test method is executed. Only when explicitly invoked. Once before all the test methods are executed.

Each time before a test method is executed. (The setUp() method is used to set up the same starting conditions for all test methods in a test class. It is automatically executed before each test method, for every test method in the class.)

When a class is instantiated, what is responsible for initializing the new object's attributes? The class's constructor. A new object's attributes are randomly initialized by the Java compiler. The class's main() method. The class's myProgram() method.

The class's constructor.

Why are the values HERE, EAST, and AHEAD (among others) written in all uppercase? It is a mistake that someone was too lazy to fix. They are important values and important values are usually written in all uppercase in Java. They are constant values and constant values are usually written in all uppercase in Java. All variable names in Java should be written in all uppercase.

They are constant values and constant values are usually written in all uppercase in Java.

Suppose that I have written the following class: public class Thing{public Thing(){//This constructor intentionally does nothing.}//In fact, this whole class intentionally does nothing.} What do I have to name the file that contains this class in order for it to compile in Java? It can be named anything; the file's name does not matter. thing.java Thing.java It can be named either "Thing.java" or "thing.java".

Thing.java

True or False: Commenting and proper indentation are important tools that can increase readability and understanding of your code and should always be used. False; I want to make my own life and the lives of others more difficult by making my code unreadable. True; I promise to always use proper indentation and put comments in my code to make editing, grading, and collaboration easier.

True; I promise to always use proper indentation and put comments in my code to make editing, grading, and collaboration easier.

Consider the following Java declaration: Jeroo jessica = new Jeroo(3, 1, SOUTH, 9); Which of the following methods in the Jeroo class are invoked by this declaration? new destructor no method is executed constructor null turn hop

constructor

Determine if Java would evaluate the following boolean expression as true or false, or if there is something (syntactically) wrong with the expression: (!x && !y) && (y && z) false syntax error true

false

Given the following if statement: if ( (this.seeJeroo(AHEAD)) || (this.seeNet(AHEAD)) ) { this.toss(); } else { this.turn(LEFT); } Which of the following if statements is logically equivalent? if !( (this.seeJeroo(AHEAD)) || (this.seeNet(AHEAD)) ) { this.turn(LEFT); } else { this.toss(); } if ( !(this.seeJeroo(AHEAD)) || !(this.seeNet(AHEAD)) ) { this.toss(); } else { this.turn(LEFT); } if ( !(this.seeJeroo(AHEAD)) && !(this.seeNet(AHEAD)) ) { this.turn(LEFT); } else { this.toss(); } if !( !(this.seeJeroo(AHEAD)) || !(this.seeNet(AHEAD)) ) { this.toss(); } else { this.turn(LEFT); }

if ( !(this.seeJeroo(AHEAD)) && !(this.seeNet(AHEAD)) ) { this.turn(LEFT); } else { this.toss(); }

What is wrong with the code fragment above, which is intended to add the integers from 1 to 10 together and print out the result, which should be 55? the sum variable must be declared inside the loop none of these (the code is correct) the loop control variable i must be declared prior to the loop The statement in the loop must be sum += i++; The statement in the loop must be sum += ++i; the sum variable must be initialized to one the test condition must be == the test condition must be <=

none of these (the code is correct)

How many times does the following Java code print "hello world"? int i=10; while( i >= 4 ) { System.out.print("hello world"); i = i + 1; } 6 6 0 none of these 1

none of these. (This is an infinite loop, because the update condition increments i, but we are starting at 10.)

You see the expression n = 100000 in some code that successfully compiles. What type can variable n NOT be? double short int long float

short (Shorts can only hold values in [-32768, 32767].)

Consider this partial class: public class MyJeroo extends Jeroo { public MyJeroo(int x, int y, CompassDirection direction, int numFlowers) { __________ // choose a line to replace this one } } Which of the following statements should fill in the blank to complete the constructor correctly? new Jeroo(x, y, direction, numFlowers); super(x, y, direction, numFlowers); Jeroo(x, y, direction, numFlowers); this(x, y, direction, numFlowers); super(x, y); this(x, y); Jeroo(x, y);

super(x, y, direction, numFlowers);

Complete this partial code: public class PlantingJeroo extends Jeroo { public void hop() { this.plant(); _______________ // choose a line to go here } } In the class above, we want PlantingJeroos to automatically plant a flower each time they move forward. Which of the following statements should be used to fill in the blank above to achieve the desired behavior? none of these hop(); super.hop(); Jeroo.hop(); this.hop();

super.hop();

A test fixture in test class is recreated (i.e. re-executed) at the start of every test (i.e. before the execution of each test method), in order for each test to be carried out in the same initial conditions. true false

true


संबंधित स्टडी सेट्स

125 Basic care and comfort Monday 1-3

View Set

Corporate Accounting 2 - Chapter 23 Statement of Cash Flows

View Set

Management of Promotion Exam 1 Quiz Chapter 3

View Set

Genetics Chapter 16 Multiple Choice

View Set

Chapter 15 - The Kennedy and Johnson Years

View Set