Unit 2 Review

Worksheet by Erin Thompson
Unit 2 Review worksheet preview image
Language
ENG
Assignments
88 classrooms used this worksheet

Test your Java skills! This Object-Oriented Programming worksheet covers classes, objects, and methods. Perfect for review.

Assume the following declaration has been made. Canines dog1 = new Canines("Muddle" , "Mutt" , 2);Which of the following statements would be the appropriate way to change the age of the dog? dog1 = new Canines(“Muddle”,”Mutt”, 3); dog1.age = 3; dog1.setAge(3); Canines.setAge(3); dog1.getAge(); What, if anything is printed as a result of executing the code segment? Consider the Flower class.Write a statement to create a new Flower object flower1 that has the name "Iris". Consider the code segment below. What, if anything, is printed when the code segment is executed? I can jump 11 times. I like pastries. It is true I can jump 47 times. I like pastries.true I can jump ab second firstabsecondc Nothing is printed because the code segment does not compile. Which of the following lines of code, if located in a method in the same class as calculatePizzaBoxes, will complie without an error? int result = calculatePizzaBoxes (45 , 9.0); int result = calculatePizzaBoxes (45.0 , 9); double result = calculatePizzaBoxes (45.0 , 9.0); double result = calculatePizzaBoxes (45 , 9.0); result = calculatePizzaBoxes (45 , 9); The SoccerBall class has been defined to store and manipulate goals for an individual player. The following methods have been defined for the class. Which of the statements, if located in the SoccerBall class, will determine the average of the player’s goals per game omitting the lowest scored game and store the result in the double variable scoreAverage? scoreAverage = sumOfGoals() / numberOfGames() - 1; scoreAverage = (sumOfGoals() - lowestGoals()) - 1; scoreAverage = (sumOfGoals() - lowestGoals()) / (numberOfGames() - 1); scoreAverage = sumOfGoals() / (numberOfGames() - 1); Consider the following code segment.What is printed as a result of executing the code segment? Which of the following method(s) can be added to the Silly class without causing a compile-time error?*This is a multiple select question. Select ALL correct answer(s).* public void fun ( String cap, int cup) public void fun ( int cup, int hair) public void fun ( int cup, int tip, int bun) public void fun ( int cup) A student has created a Superhero class. The class contains variables to represent the following:A String variable called name to represent the name of the superheroAn int variable called age to represent the age of the superheroA double called saves which looks at the number of people saved where assists are valued at 0.5. The object batman will be declared as type Superhero. Which of the following statements is accurate? An instance of the batman class is Superhero An instance of a Superhero object is saves An attribute of the batman object is age An attribute of age is int An attribute of name is Superhero An instance of the saves class is batman Given the Cat class, does Cat myCat; correctly create an instance of a new cat object? Yes No

Object-Oriented Programming Java Programming Computer Science Education Class and Object Methods
Use This Worksheet