Chapter 15 AP Comp Sci - Working with Methods

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Given the Artifact class below... class Artifact { int age = 350; public void date() { int age = 200; System.out.println("Artifact is " + age + " years old"); } } When the following date() method is run, what value will be used for the age variable?

200

What do you call a method that safely returns a copy of private data to external code?

Accessor

When a class implements an interface, which of the following conditions must be met to successfully create that class?

All interface methods must be implemented

Given the following two method signatures on the Artifact class... public void translate(String language) public void translate(int year) ...and the following code that creates an Artifact object... Artifact tablet = new Artifact(); ...which of the following answers correctly demonstrates how to call the translate() method?

Both of these will work

If you don't want external code to change your class data to unexpected or invalid values, and you want the freedom to redesign your internal variables without breaking external code, what OOP concept should you use?

Data Encapsulation

In programming, what do we call the process of breaking a larger task down into a series of smaller, well-defined parts?

Functional decomposition

For an interface named ITranslatable, which of the following is a valid Java filename for that interface?

ITranslatable.java

Where do you declare variables with "local" scope?

Inside the curly braces marking the body of a method, if() statement or loop

Which of the following best describes a set of overloaded methods?

Multiple methods on the same class with the same name, but different parameters

What do we call a method that will update a private property after verifying the incoming data is valid?

Mutator

Which of the following is not a valid reason for overloading a method?

None of these are valid reasons

if you have marked a method as "private", where can that method be called from?

Only from within other methods on the same class

Which of the following best describes preconditions and postconditions?

Preconditions are things that must be true before a method is called; postconditions are things that are true after a method has finished running

If the Artifact class successfully implements the ITranslatable interface, then given the line of code below, which statement is true? ITranslatable artifact = new Artifact();

The artifact reference can only be used to access the methods defined in the Itranslatable interface

In OOP, what does the concept of "cohesion" describe?

The level of focus a class has on one task or concept

In OOP, what does the concept of "coupling" describe?

The level of reliance a class has on other classes

Which of the following best describes a variable that has a "class" scope?

The variable is created when the class is created and can be accessed from any class method

Given the Artifact class below... class Artifact { int age = 350; public void readInscription(String language) { String translation = ""; } } When the following code statements run, which variable will have the longest lifespan? Artifact tablet = newArtifact(); tablet.readInscription("English");

age

Which of the following statements successfully declares the Artifact class as implementing the ITranslatable interface?

public class Artifact implements ITranslatable

Given the following two method signatures on the Artifact class... public void translate(String language) public void translate(int year) ...and the following code that creates an Artifact object... Artifact tablet = new Artifact(); ...which of the following statements will not correctly call the translate() method?

tablet.translate(false);


Ensembles d'études connexes

Oxford Word Skills Advanced - Unit 21 I can talk about holidays

View Set

PMP 1: Project Management Framework

View Set

Test 3 Compensation and Benefits Dr. B

View Set

Research Methods in Psychology chapter 6

View Set

Fundamentals of Oral Communication

View Set