Deck 3: Using Methods, Classes, and Objects
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/68
Play
Full screen (f)
Deck 3: Using Methods, Classes, and Objects
1
An object is a ____ of a class.
A) constant
B) member
C) method
D) field
A) constant
B) member
C) method
D) field
B
2
Application classes frequently instantiate objects that use the objects of other classes.
True
3
The interface is the part of a method that the method's client does not see.
False
4
When a value is returned from a method, you are required to use the value when the method is called.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
5
You can identify a class that is an application because it contains a public static void main() method.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
6
An application's main() method must have a void return type.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
7
The method ____ is the first line of a method.
A) argument
B) address
C) statement
D) declaration
A) argument
B) address
C) statement
D) declaration
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
8
The ____ method executes first in an application, regardless of where you physically place it within its class.
A) start()
B) run()
C) main()
D) execute()
A) start()
B) run()
C) main()
D) execute()
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
9
Any class can contain an unlimited number of methods.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
10
A(n) ____ causes a value to be sent from a called method back to the calling method.
A) return statement
B) method statement
C) instantiation
D) inheritance relationship
A) return statement
B) method statement
C) instantiation
D) inheritance relationship
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
11
A method body provides information about how other methods can interact with it.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
12
You can write your own constructor methods; but when you don't write a constructor method for a class object, Java writes one for you.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
13
The arguments in a method call are often referred to as ____.
A) constants
B) concept parameters
C) actual parameters
D) argument lists
A) constants
B) concept parameters
C) actual parameters
D) argument lists
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
14
Data items you use in a call to a method are called ____.
A) arguments
B) instance variables
C) method declarations
D) headers
A) arguments
B) instance variables
C) method declarations
D) headers
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
15
A(n) ____ is a program module that contains a series of statements that carry out a task.
A) argument
B) method
C) application
D) declaration
A) argument
B) method
C) application
D) declaration
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
16
When a variable ceases to exist at the end of a method, programmers say the variable ____.
A) is undeclared
B) is out of memory range
C) goes out of scope
D) is lost
A) is undeclared
B) is out of memory range
C) goes out of scope
D) is lost
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
17
A method's identifier must be more than one word, must have no embedded spaces, and cannot be a Java keyword.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
18
A(n) ____ variable is known only within the boundaries of the method.
A) method
B) local
C) double
D) instance
A) method
B) local
C) double
D) instance
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
19
____ is the encapsulation of method details within a class.
A) An interface
B) A calling method
C) Implementation hiding
D) Instantiation
A) An interface
B) A calling method
C) Implementation hiding
D) Instantiation
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
20
Parentheses in a method declaration contain parameters that are funneled into the method.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
21
When an application is run, the method that must be executed first must be named ____.
A) first()
B) void()
C) main()
D) final()
A) first()
B) void()
C) main()
D) final()
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
22
To execute a method, you ____________________ it from another method.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
23
Assigning ____ to a field means that no other classes can access the field's values.
A) user rights
B) protected access
C) key access
D) private access
A) user rights
B) protected access
C) key access
D) private access
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
24
Normally, you declare constructors to be ____________________ so that other classes can instantiate objects that belong to the class.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
25
The name of the ____ is always the same as the name of the class whose objects it creates.
A) method
B) constructor
C) argument
D) variable
A) method
B) constructor
C) argument
D) variable
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
26
A(n) ____ constructor is one that requires no arguments.
A) class
B) default
C) explicit
D) write
A) class
B) default
C) explicit
D) write
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
27
Method names that begin with ____ and set are very typical.
A) next
B) call
C) read
D) get
A) next
B) call
C) read
D) get
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
28
____ parameters are variables in a method declaration that accept the values from the actual parameters.
A) System
B) Formal
C) Public
D) Static
A) System
B) Formal
C) Public
D) Static
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
29
Which of the following is NOT an initial value assigned to an object's data field by a default constructor?
A) numeric fields set to 0
B) Boolean fields set to true
C) character fields set to Unicode '\u0000'
D) a field of object references set to null
A) numeric fields set to 0
B) Boolean fields set to true
C) character fields set to Unicode '\u0000'
D) a field of object references set to null
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
30
When you think in an object-oriented manner, everything is a(n) ____________________.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
31
Access specifiers are also called access ____________________.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
32
You are ____ required to write a constructor method for a class.
A) never
B) always
C) sometimes
D) often
A) never
B) always
C) sometimes
D) often
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
33
Methods that retrieve values are called ____ methods.
A) static
B) accessor
C) class
D) mutator
A) static
B) accessor
C) class
D) mutator
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
34
For ease in locating class methods, many programmers store them in ____ order.
A) chronological
B) type
C) alphabetical
D) numeric
A) chronological
B) type
C) alphabetical
D) numeric
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
35
A(n) ____________________ is a number appended to a field, typically an ID number or account number.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
36
Public classes are accessible by all objects, which means that public classes can be ____, or used as a basis for any other class.
A) saved
B) extended
C) copied
D) used
A) saved
B) extended
C) copied
D) used
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
37
In order to allocate memory for an object, you use the ____ operator.
A) new
B) main
C) type
D) return
A) new
B) main
C) type
D) return
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
38
A unique identifier is most likely used as a ____ key in a database.
A) special
B) public
C) static
D) primary
A) special
B) public
C) static
D) primary
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
39
A(n) ____ method is a method that creates and initializes class objects.
A) constructor
B) accessor
C) non-static
D) instance
A) constructor
B) accessor
C) non-static
D) instance
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
40
Methods used with object instantiations are called ____ methods.
A) accessor
B) internal
C) static
D) instance
A) accessor
B) internal
C) static
D) instance
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
41
Match each term with the correct statement below.
-The first line of a method
A)return statement
B)header
C)instance variables
D)method’s signature
E)formal parameters
F)static method
G)data fields
H)parameter type
I)class user
-The first line of a method
A)return statement
B)header
C)instance variables
D)method’s signature
E)formal parameters
F)static method
G)data fields
H)parameter type
I)class user
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
42
Match each term with the correct statement below.
-Variables in the method declaration that accept the values from the actual parameters
A)return statement
B)header
C)instance variables
D)method’s signature
E)formal parameters
F)static method
G)data fields
H)parameter type
I)class user
-Variables in the method declaration that accept the values from the actual parameters
A)return statement
B)header
C)instance variables
D)method’s signature
E)formal parameters
F)static method
G)data fields
H)parameter type
I)class user
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
43
How does a programmer use a method?
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
44
Match each term with the correct statement below.
-Data components of a class
A)return statement
B)header
C)instance variables
D)method’s signature
E)formal parameters
F)static method
G)data fields
H)parameter type
I)class user
-Data components of a class
A)return statement
B)header
C)instance variables
D)method’s signature
E)formal parameters
F)static method
G)data fields
H)parameter type
I)class user
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
45
Which is more important: the order in which you place methods' bodies, or the order in which you call methods? Please explain.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
46
What are the four components of a method header?
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
47
When talking about inheritance, why do programmers use the phrase "is a"?
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
48
How do you create an instance of a class? Provide an example.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
49
Match each term with the correct statement below.
-Variables you declare within a class, but outside of any method
A)return statement
B)header
C)instance variables
D)method’s signature
E)formal parameters
F)static method
G)data fields
H)parameter type
I)class user
-Variables you declare within a class, but outside of any method
A)return statement
B)header
C)instance variables
D)method’s signature
E)formal parameters
F)static method
G)data fields
H)parameter type
I)class user
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
50
Match each term with the correct statement below.
-Included within the method declaration parentheses
A)return statement
B)header
C)instance variables
D)method’s signature
E)formal parameters
F)static method
G)data fields
H)parameter type
I)class user
-Included within the method declaration parentheses
A)return statement
B)header
C)instance variables
D)method’s signature
E)formal parameters
F)static method
G)data fields
H)parameter type
I)class user
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
51
When the parentheses of a method are empty, what does this indicate?
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
52
Match each term with the correct statement below.
-Are called class methods
A)return statement
B)header
C)instance variables
D)method’s signature
E)formal parameters
F)static method
G)data fields
H)parameter type
I)class user
-Are called class methods
A)return statement
B)header
C)instance variables
D)method’s signature
E)formal parameters
F)static method
G)data fields
H)parameter type
I)class user
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
53
Explain the difference between public access and private access when defining a class.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
54
Match each term with the correct statement below.
-The combination of the method name and the number, types, and order of arguments
A)return statement
B)header
C)instance variables
D)method’s signature
E)formal parameters
F)static method
G)data fields
H)parameter type
I)class user
-The combination of the method name and the number, types, and order of arguments
A)return statement
B)header
C)instance variables
D)method’s signature
E)formal parameters
F)static method
G)data fields
H)parameter type
I)class user
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
55
Describe how you can use multiple arguments in a method.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
56
Why are hidden implementation methods often referred to as existing in a black box?
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
57
Match each term with the correct statement below.
-An application or a class that instantiates objects of another prewritten class
A)return statement
B)header
C)instance variables
D)method’s signature
E)formal parameters
F)static method
G)data fields
H)parameter type
I)class user
-An application or a class that instantiates objects of another prewritten class
A)return statement
B)header
C)instance variables
D)method’s signature
E)formal parameters
F)static method
G)data fields
H)parameter type
I)class user
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
58
What happens to a value returned from a method?
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
59
Match each term with the correct statement below.
-Used to return a value back to the calling method
A)return statement
B)header
C)instance variables
D)method’s signature
E)formal parameters
F)static method
G)data fields
H)parameter type
I)class user
-Used to return a value back to the calling method
A)return statement
B)header
C)instance variables
D)method’s signature
E)formal parameters
F)static method
G)data fields
H)parameter type
I)class user
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
60
Does a programmer need to write every class he or she uses? Why or why not?
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
61
Parentheses - may contain data to be sent to the method, but may be empty if no outside data is required
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
62
A major advantage of a method is that it is easily reusable. What does it mean to reuse a method and what are the advantages of doing so?
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
63
Methods use memory locations to hold values of variables. Describe the process of memory allocation and variable scope.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
64
When creating a method that requires multiple parameters, why would a programmer need to understand a method's signature, and why must a method call match the called method's signature?
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
65
public int getStudentNum()
{
return studentNum;
}
In the above code, identify if the method is a mutator method or an accessor method. Describe how the two types of methods differ and how they are similar.
{
return studentNum;
}
In the above code, identify if the method is a mutator method or an accessor method. Describe how the two types of methods differ and how they are similar.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
66
Explain the purpose of a return type of a method. Describe the return value of a method that returns no data.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
67
Describe fully qualified identifiers and explain why they are necessary.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck
68
Write a valid class header with public access. Assign a legal identifier of your choice. Then write the body of the class that contains one data field named myPractice with a data type of double. Be sure to include any necessary curly braces and semicolons.
Unlock Deck
Unlock for access to all 68 flashcards in this deck.
Unlock Deck
k this deck