Deck 4: Defining Classes I
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/45
Play
Full screen (f)
Deck 4: Defining Classes I
1
An object of class A is an instance of class A.
True
2
The new operator:
A)allocates memory
B)is used to create an object of a class
C)associates an object with a variable that names it.
D)All of the above.
A)allocates memory
B)is used to create an object of a class
C)associates an object with a variable that names it.
D)All of the above.
D
3
A set method is:
A)an accessor method
B)a mutator method
C)a recursive method
D)none of the above
A)an accessor method
B)a mutator method
C)a recursive method
D)none of the above
B
4
An invocation of a method that returns a value can be used as an expression any place that a value of the Type_Returned can be used.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
5
The Java language supports global variables.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
6
A variable whose meaning is confined to an object of a class is called:
A)instance variable
B)local variable
C)global variable
D)none of the above
A)instance variable
B)local variable
C)global variable
D)none of the above
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
7
A method that performs some action other than returning a value is called a __________ method.
A)null
B)void
C)public
D)private
A)null
B)void
C)public
D)private
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
8
A _________ states what is assumed to be true when the method is called.
A)prescript
B)postscript
C)precondition
D)postcondition
A)prescript
B)postscript
C)precondition
D)postcondition
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
9
In Java,call-by-value is only used with:
A)objects
B)primitive types
C)this
D)all of the above
A)objects
B)primitive types
C)this
D)all of the above
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
10
The name of a method and the list of ________ types in the heading of the method definition is called the method signature.
A)parameter
B)argument
C)return
D)primitive
A)parameter
B)argument
C)return
D)primitive
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
11
Accessor methods:
A)return something equivalent to the value of an instance variable.
B)promotes abstraction
C)both A and B
D)none of the above
A)return something equivalent to the value of an instance variable.
B)promotes abstraction
C)both A and B
D)none of the above
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
12
Java has a way of officially hiding details of a class definition.To hide details,you mark them as _________.
A)public
B)protected
C)private
D)all of the above
A)public
B)protected
C)private
D)all of the above
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
13
A program whose only task is to test a method is called a:
A)driver program
B)stub
C)bottom-up test
D)recursive method
A)driver program
B)stub
C)bottom-up test
D)recursive method
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
14
Two methods that are expected to be in all Java classes are:
A)getName and setName
B)toString and equals
C)compareTo and charAt
D)toLowerCase and toUpperCase
A)getName and setName
B)toString and equals
C)compareTo and charAt
D)toLowerCase and toUpperCase
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
15
When the parameters in a method have the same as instance variables you can differentiate them by using the _____ parameter.
A)String
B)hidden
C)default
D)this
A)String
B)hidden
C)default
D)this
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
16
In Java,a block is delimited by:
A))
B)/* */
C)" "
D){ }
A))
B)/* */
C)" "
D){ }
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
17
The body of a method that returns a value must contain at least one _________ statement.
A)void
B)invocation
C)thows
D)return
A)void
B)invocation
C)thows
D)return
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
18
A more eloquent approach in implementing mutator methods is to return a ________ value.
A)int
B)char
C)boolean
D)double
A)int
B)char
C)boolean
D)double
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
19
The parameter this refers to
A)instance variables
B)local variables
C)global variables
D)the calling object
A)instance variables
B)local variables
C)global variables
D)the calling object
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
20
A variable whose meaning is confined to a method definition is called an/a
A)instance variable
B)local variable
C)global variable
D)none of the above
A)instance variable
B)local variable
C)global variable
D)none of the above
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
21
What is the purpose of the new operator?
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
22
It is considered good programming practice to validate a value passed to a mutator method before setting the instance variable.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
23
When you give a command to run a Java program,the runtime system invokes the class constructor.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
24
Java supports operator overloading.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
25
Inside a Java method definition,you can use the keyword this as a name for the calling object.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
26
Write a method called power the computes x< sup >n< /sup > where x and n and positive integers.The method has two integer parameters and returns a value of type long.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
27
Define the terms arguments and parameters.How are they different?
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
28
Create a class named Appointment that contains instance variables startTime,endTime,dayOfWeek valid values are Sunday through Saturday),and a date which consists of a month,day and year.All times should be in military time,therefore it is appropriate to use integers to represent the time.Create the appropriate accessor and mutator methods.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
29
Write a Java method that returns the value of PI,where PI = 3.1415926535.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
30
Boolean expressions may be used to control if-else or while statements.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
31
Discuss a situation in which it is appropriate to use the this parameter.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
32
Write a method called Greeting that displays a personalized greeting given a first name.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
33
The modifier private means that an instance variable can be accessed by name outside of the class definition.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
34
In a method invocation,there must be exactly the same number of arguments in parentheses as there are formal parameters in the method definition heading.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
35
Only the default constructor has the this parameter.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
36
Write a Java method that prints the phrase "Five purple people eaters were seen munching Martians".
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
37
Write a method called isEqual that returns a Boolean value.The method compares two integers for equality.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
38
Method overloading is when two or more methods of the same class have the same name but differ in number or types of parameters.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
39
Discuss the public and private modifiers in context of methods and instance variables.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
40
Mutator methods can return integer values indicating if the change of the instance variable was a success.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
41
Write preconditions and postconditions for the power method you wrote in question #4.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
42
Discuss the importance of accessor and mutator methods and how they apply to the abstraction concept.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
43
Write a Java class that represents a Student with instance variables name,id,and gpa.Include constructors,accessor,mutator and any facilitator methods you may need.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
44
Add two constructors to the Appointment class created in question #9.Include a default constructor and a constructor to initialize an Appointment to suitable arguments.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck
45
Write a driver program to test your Student class created in question #14.
Unlock Deck
Unlock for access to all 45 flashcards in this deck.
Unlock Deck
k this deck