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
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/44
Play
Full screen (f)
Deck 4: Defining Classes I
1
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.
True
2
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
B
3
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
D
4
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 44 flashcards in this deck.
Unlock Deck
k this deck
5
An object of class A is an instance of class A.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
6
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 44 flashcards in this deck.
Unlock Deck
k this deck
7
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 44 flashcards in this deck.
Unlock Deck
k this deck
8
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.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
9
The Java language supports global variables.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
10
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 44 flashcards in this deck.
Unlock Deck
k this deck
11
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 44 flashcards in this deck.
Unlock Deck
k this deck
12
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 44 flashcards in this deck.
Unlock Deck
k this deck
13
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 44 flashcards in this deck.
Unlock Deck
k this deck
14
When you want the parameters in a method to be the same as the instance variables you can use 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 44 flashcards in this deck.
Unlock Deck
k this deck
15
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 44 flashcards in this deck.
Unlock Deck
k this deck
16
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 44 flashcards in this deck.
Unlock Deck
k this deck
17
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 44 flashcards in this deck.
Unlock Deck
k this deck
18
In Java,a block is delimited by:
(a)( )
(b)/* */
(c)" "
(d){ }
(a)( )
(b)/* */
(c)" "
(d){ }
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
19
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 44 flashcards in this deck.
Unlock Deck
k this deck
20
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
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
21
Write a method called Greeting that displays a personalized greeting given a first name.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
22
Mutator methods can return integer values indicating if the change of the instance variable was a success.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
23
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 44 flashcards in this deck.
Unlock Deck
k this deck
24
Boolean expressions may be used to control if-else or while statements.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
25
Java supports operator overloading.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
26
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 44 flashcards in this deck.
Unlock Deck
k this deck
27
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 44 flashcards in this deck.
Unlock Deck
k this deck
28
Only the default constructor has the this parameter.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
29
Discuss the public and private modifiers in context of methods and instance variables.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
30
Discuss the importance of accessor and mutator methods and how they apply to the abstraction concept.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
31
Define the terms arguments and parameters.How are they different?
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
32
What is the purpose of the new operator?
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
33
Write a Java method that prints the phrase "Five purple people eaters were seen munching Martians".
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
34
Write a method called power the computes xn 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 44 flashcards in this deck.
Unlock Deck
k this deck
35
Write a Java method that returns the value of PI,where PI = 3.1415926535.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
36
Discuss a situation in which it is appropriate to use the this parameter.
Unlock Deck
Unlock for access to all 44 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 44 flashcards in this deck.
Unlock Deck
k this deck
38
When you give a command to run a Java program,the runtime system invokes the class constructor.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
39
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 44 flashcards in this deck.
Unlock Deck
k this deck
40
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 44 flashcards in this deck.
Unlock Deck
k this deck
41
Write a driver program to test your Student class created in question #14.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
42
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 44 flashcards in this deck.
Unlock Deck
k this deck
43
Write preconditions and postconditions for the power method you wrote in question #4.
Unlock Deck
Unlock for access to all 44 flashcards in this deck.
Unlock Deck
k this deck
44
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 44 flashcards in this deck.
Unlock Deck
k this deck