Exam 5: Writing Classes

arrow
  • Select Tags
search iconSearch Question
flashcardsStudy Flashcards
  • Select Tags

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:
Verified

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:
Verified

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:
Verified

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)

Explain why method overloading is useful.

(Essay)
4.7/5
(43)

What is encapsulation? How can it be enforced in Java?

(Essay)
4.9/5
(36)

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)

A variable can always be referenced anywhere in a program.

(True/False)
4.8/5
(42)

What is the difference between an object and a class?

(Essay)
4.8/5
(42)

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
close modal

Filters

  • Essay(0)
  • Multiple Choice(0)
  • Short Answer(0)
  • True False(0)
  • Matching(0)