Exam 5: Writing Classes
Exam 1: Introduction40 Questions
Exam 2: Data and Expressions40 Questions
Exam 3: Using Classes and Objects40 Questions
Exam 4: Conditionals and Loops40 Questions
Exam 5: Writing Classes40 Questions
Exam 6: Graphical User Interfaces40 Questions
Exam 7: Arrays40 Questions
Exam 8: Inheritance40 Questions
Exam 9: Polymorphism39 Questions
Exam 11: Recursion40 Questions
Exam 10: Exceptions40 Questions
Exam 12: Searching and Sorting40 Questions
Exam 13: Trees40 Questions
Exam 14: Introduction to Collections and Stacks40 Questions
Exam 15: Heaps and Priority Queues40 Questions
Exam 16: Graphs40 Questions
Select questions type
Methods that can be called directly through the class name and do not need to have an object instantiated are called _________________.
Free
(Multiple Choice)
4.7/5
(36)
Correct Answer:
C
Write a method called maxOfThree that accepts three integer parameters and returns the largest of the three.
Free
(Essay)
4.8/5
(33)
Correct Answer:
public int maxOfThree(int firstInt, int secondInt, int thirdInt) {
if(firstInt >= secondInt && firstInt >= thirdInt)
return firstInt;
else if(secondInt >= firstInt && secondInt >= thirdInt)
return secondInt;
else
return thirdInt;
}
A method that has multiple definitions is an __________________ method.
Free
(Multiple Choice)
4.8/5
(41)
Correct Answer:
A
When an object is passed to a method, the actual and formal parameters become aliases.
(True/False)
4.9/5
(35)
Which of the following object-oriented principles refers to the fact that an object should have its data guarded from inappropriate access?
(Multiple Choice)
4.8/5
(34)
__________________ parameters are the values that are used when calling a method.
(Multiple Choice)
4.9/5
(37)
Write a method called randomAverage that generates 100 random integers in the range 1 to 100 (inclusive) and returns their average. You may assume that the class has a static Random object called generator already declared and instantiated.
(Short Answer)
4.9/5
(43)
Consider the following method.
public void changeValues(int i, Card c) {
i = 15;
c.setSuit(“Clubs”);
}
Now consider the following snippet of code that calls the method defined above.
int num = 12;
Card fiveOfSpades = new Card(5, “Spades”);
System.out.println(“Before method call:”);
System.out.println(num);
System.out.println(fiveOfSpades.getSuit());
changeValues(num, fiveOfSpades);
System.out.println(“After method call:”);
System.out.println(num);
System.out.println(fiveOfSpades);
What is the output of this code?
(Essay)
4.8/5
(34)
There are times when it is appropriate to return data from a method of a type that is inconsistent with the return type specified in the method header.
(True/False)
4.9/5
(48)
Write a method called countSpaces that takes in a String as a parameter and returns an integer that represents the number of space characters (' ') contained in the string, false otherwise..
(Short Answer)
4.9/5
(49)
An object can be thought of as a blueprint for a set of classes.
(True/False)
4.9/5
(35)
Which of the following types of methods do not have any return type (not even a void return type)?
(Multiple Choice)
4.8/5
(34)
In a class that has variables called height and width, methods called getHeight() and getWidth() are examples of accessor methods.
(True/False)
4.8/5
(25)
A(n) ________________ is a step-by-step process for solving a problem.
(Multiple Choice)
4.8/5
(38)
Write a method called randomInRange that takes in two numbers representing a range. Print an error message and return zero if the second parameter is less than the first. Otherwise, the method should return a randomly generated integer in that range (inclusive). You may assume that the class has a static Random object called generator already declared and instantiated.
(Short Answer)
4.8/5
(43)
All methods (with the exception of constructors) must specify a return type. What is the return type for a method that does not return any values?
(Multiple Choice)
4.9/5
(32)
Showing 1 - 20 of 40
Filters
- Essay(0)
- Multiple Choice(0)
- Short Answer(0)
- True False(0)
- Matching(0)