Final exam practice Quiz

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

Consider this code segment: List<Integer> aList = new ArrayList<Integer>(); for (int i = 11; i < 15; i++) { aList.add(i); } What output is printed by the following statement? aList.add(1, 10); aList.remove(0); System.out.println(aList.get(0)); 13 an error occurs 12 10 11 14

10

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

A constructor's return type must be declared void.

What does the Scanner class consider to be a word (assuming the default delimiters are used)? Any series of non-whitespace characters Whitespace characters A single character Any series of characters

Any series of non-whitespace characters

What is output by the execution of the following method? public void myProgram() { Jeroo bobby = new Jeroo(2); // Created with two flowers add(bobby, 6, 6); bobby.plant(); Jeroo jessica = new Jeroo(1); // Created with one flower add(jessica, 3, 3); bobby = jessica; jessica.plant(); if (bobby.hasFlower()) { System.out.println("Bobby has a flower."); } else { System.out.println( "Bobby has NO flowers."); } } No output occurs. Bobby has NO flowers. Bobby has a flower.

Bobby has NO flowers.

What does delegation mean? Delegation means an object creates another object. Delegation means the object's methods are split into simple functions. Delegation means an object uses another object to perform an action. Delegation means the object contains methods for a variety of specific situations.

Delegation means an object uses another object to perform an action.

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? destructor no method is executed null turn new hop constructor

constructor

If you are writing a Java class and want to use the Jeroo class in it, which of the following statements must appear before your class' declaration? (Hint: Greenfoot4Sofia inserts it automatically in most cases, but it is always required.) implements sofia.micro.jeroo.*; extends sofia.micro.jeroo.*; extends Jeroo import Jeroo; implements Jeroo import sofia.micro.jeroo.*;

import sofia.micro.jeroo.*;

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; } 1 0 none of the these. 6 6

none of the these.

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; } none of the these. 0 6 1 6

none of the these.

What is a stream? It is a sequence of text or data coming from some source or going to some destination. It is the memory used by your program. It is a sequence of method calls in a program. It is the text located inside of a file.

It is a sequence of text or data coming from some source or going to some destination.

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.

True or False: In our Jeroo simulation, the island's x-axis and y-axis both start at zero in the northwest corner. False; the island's x-axis and y-axis both start at zero in the northeast corner. False; the island's x-axis and y-axis both start at zero in the southwest corner. False; the island's x-axis and y-axis both start at zero in the southeast corner. True.

True

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 this.hop(); hop(); super.hop(); Jeroo.hop();

super.hop();

Assume that a Jeroo is standing on a flower--in fact, on many flowers, all in the same grid cell. Consider the following incomplete method for picking all the flowers: /** * Pick up all the flowers where the Jeroo is right now. */ public void pickAllFlowers() { if (this.seesFlower(HERE)) { this.pick(); __________; // Complete this line } } Select the statement that most appropriately fills in the blank to complete this method. this.hop(); super.hop(); this.pickAllFlowers(); super.pick(); while none of these choices will work

this.pickAllFlowers();


Set pelajaran terkait

Art History Class 1: Renaissance, Mannerism, Counter-Reformation

View Set

8.10A Race in WWII - Main Idea CHALLENGE

View Set

Mood, Adjustment, and Dementia Disorders NCLEX 3000

View Set

Pharmacology: Chapter 56: Drugs for Womens Reproductive Health and Menopause

View Set

econ of corp finance homework problems

View Set