Deck 6: A First Look at Classes
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/58
Play
Full screen (f)
Deck 6: A First Look at Classes
1
Methods that operate on an object's fields are called __________.
A) instance methods
B) instance variables
C) private methods
D) public methods
A) instance methods
B) instance variables
C) private methods
D) public methods
A
2
A method that gets a value from a class's field but does not change it is known as a mutator method.
False
3
The term "no-arg constructor" is applied to any constructor that does not accept arguments.
True
4
The java.lang package is automatically imported into all Java programs.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
5
When a local variable in an instance method has the same name as an instance field, the instance field hides the local variable.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
6
When an object is passed as an argument to a method, the object's address is passed into the method's parameter variable.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
7
A class's responsibilities include __________.
A) the things a class is responsible for knowing
B) the things a class is responsible for doing
C) both of these
D) neither of these
A) the things a class is responsible for knowing
B) the things a class is responsible for doing
C) both of these
D) neither of these
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
8
Instance methods do not have the key word static in their headers.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
9
Data hiding (which means that critical data stored inside the object is protected from code outside the object) is accomplished in Java by __________.
A) using the public access specifier on the class methods
B) using the private access specifier on the class methods
C) using the private access specifier on the class fields
D) using the private access specifier on the class definition
A) using the public access specifier on the class methods
B) using the private access specifier on the class methods
C) using the private access specifier on the class fields
D) using the private access specifier on the class definition
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
10
An object can store data.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
11
A group of related classes is called a(n) __________.
A) archive
B) package
C) collection
D) attachment
A) archive
B) package
C) collection
D) attachment
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
12
A class is not an object. It is a description of an object.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
13
A constructor is a method that is automatically called when an object is created.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
14
The term "default constructor" is applied to the first constructor written by the author of the class.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
15
When an object is created, the attributes associated with the object are called __________.
A) instance fields
B) class instances
C) instance methods
D) fixed attributes
A) instance fields
B) class instances
C) instance methods
D) fixed attributes
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
16
Shadowing is the term used to describe where the field name is hidden by the name of a local or parameter variable.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
17
The public access specifier for a field indicates that the field may not be accessed by statements outside the class.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
18
A method that stores a value in a class's field or in some other way changes the value of a field is known as a mutator method.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
19
An access specifier indicates how a class may be accessed.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
20
Instance methods should be declared static.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
21
The following statement is an example of __________.
import java.util.*;
A) an explicit import statement
B) an unconditional import statement
C) a wildcard import statement
D) a conditional import statement
import java.util.*;
A) an explicit import statement
B) an unconditional import statement
C) a wildcard import statement
D) a conditional import statement
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
22
The scope of a private instance field is __________.
A) the instance methods of the same class
B) inside the class but not inside any method in that class
C) inside the parentheses of a method header
D) the method in which it is defined
A) the instance methods of the same class
B) inside the class but not inside any method in that class
C) inside the parentheses of a method header
D) the method in which it is defined
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
23
For the following code, which statement is not true?
public class Sphere
{
Private double radius;
Public double x;
Private double y;
Private double z;
}
A) The z field is available to code written outside the Sphere class.
B) The radius field is not available to code written outside the Sphere class.
C) The radius, x, y, and z fields are members of the Sphere class.
D) The x field is available to code that is written outside the Sphere class.
public class Sphere
{
Private double radius;
Public double x;
Private double y;
Private double z;
}
A) The z field is available to code written outside the Sphere class.
B) The radius field is not available to code written outside the Sphere class.
C) The radius, x, y, and z fields are members of the Sphere class.
D) The x field is available to code that is written outside the Sphere class.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
24
Class objects normally have __________ that perform useful operations on their data, but primitive variables do not.
A) fields
B) relationships
C) methods
D) instances
A) fields
B) relationships
C) methods
D) instances
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
25
After the header, the body of the method appears inside a set of __________.
A) braces, { }
B) parentheses, ( )
C) brackets, [ ]
D) double quotes, " "
A) braces, { }
B) parentheses, ( )
C) brackets, [ ]
D) double quotes, " "
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
26
Which symbol indicates that a member is private a UML diagram?
A) -
B) *
C) #
D) +
A) -
B) *
C) #
D) +
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
27
A constructor __________.
A) always accepts two arguments
B) has the same name as the class
C) has the return type of void
D) always has a private access specifier
A) always accepts two arguments
B) has the same name as the class
C) has the return type of void
D) always has a private access specifier
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
28
The following statement is an example of __________.
import java.util.Scanner;
A) an explicit import statement
B) an unconditional import statement
C) a wildcard import statement
D) a conditional import statement
import java.util.Scanner;
A) an explicit import statement
B) an unconditional import statement
C) a wildcard import statement
D) a conditional import statement
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
29
__________ refers to combining data and code into a single object.
A) Data hiding
B) Abstraction
C) The constructor
D) Encapsulation
A) Data hiding
B) Abstraction
C) The constructor
D) Encapsulation
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
30
To indicate the data type of a variable in a UML diagram, you enter __________.
A) the variable name followed by the data type
B) the variable name followed by a colon and the data type
C) the class name followed by the variable name followed by the data type
D) the data type followed by the variable name
A) the variable name followed by the data type
B) the variable name followed by a colon and the data type
C) the class name followed by the variable name followed by the data type
D) the data type followed by the variable name
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
31
Which of the following is not involved in identifying the classes to be used when developing an object-oriented application?
A) a description of the problem domain
B) the code
C) a refined list of nouns that include only those relevant to the problem
D) all the nouns are identified
A) a description of the problem domain
B) the code
C) a refined list of nouns that include only those relevant to the problem
D) all the nouns are identified
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
32
For the following code, which statement is not true?
public class Circle
{
Private double radius;
Public double x;
Private double y;
}
A) The y field is available to code written outside the Circle class.
B) The radius field is not available to code written outside the Circle class.
C) The radius, x, and y fields are members of the Circle class.
D) The x field is available to code that is written outside the Circle class.
public class Circle
{
Private double radius;
Public double x;
Private double y;
}
A) The y field is available to code written outside the Circle class.
B) The radius field is not available to code written outside the Circle class.
C) The radius, x, and y fields are members of the Circle class.
D) The x field is available to code that is written outside the Circle class.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
33
What does the following UML diagram entry mean? + setHeight(h : double) : void
A) a public method with a parameter of data type double that does not return a value
B) a private field called setHeight that is a double data type
C) a private method with no parameters that returns a double data type
D) a public field called setHeight that is a double data type
A) a public method with a parameter of data type double that does not return a value
B) a private field called setHeight that is a double data type
C) a private method with no parameters that returns a double data type
D) a public field called setHeight that is a double data type
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
34
It is common practice in object-oriented programming to make all of a class's __________.
A) fields private
B) methods private
C) fields public
D) fields and methods public
A) fields private
B) methods private
C) fields public
D) fields and methods public
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
35
You should not define a class that is dependent on the values of other class fields __________.
A) in order to keep it current
B) because it is redundant
C) in order to avoid having stale data
D) because it should be defined in another class
A) in order to keep it current
B) because it is redundant
C) in order to avoid having stale data
D) because it should be defined in another class
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
36
Which symbol indicates that a member is public in a UML diagram?
A) -
B) *
C) #
D) +
A) -
B) *
C) #
D) +
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
37
A constructor is a method that __________.
A) returns an object of the class
B) never receives any arguments
C) performs initialization or setup operations
D) removes the object from memory
A) returns an object of the class
B) never receives any arguments
C) performs initialization or setup operations
D) removes the object from memory
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
38
One or more objects may be created from a(n) __________.
A) field
B) method
C) instance
D) class
A) field
B) method
C) instance
D) class
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
39
A class specifies the __________ and __________ that a particular type of object has.
A) relationships, methods
B) fields, object names
C) fields, methods
D) relationships, object names
A) relationships, methods
B) fields, object names
C) fields, methods
D) relationships, object names
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
40
Another term for an object of a class is a(n) __________.
A) access specifier
B) instance
C) member
D) method
A) access specifier
B) instance
C) member
D) method
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
41
When an object is passed as an argument to a method, what is passed into the method's parameter variable?
A) the class name
B) the object's memory address
C) the values for each field
D) the method names
A) the class name
B) the object's memory address
C) the values for each field
D) the method names
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
42
When you work with a __________, you are using a storage location that holds a piece of data.
A) primitive variable
B) reference variable
C) numeric literal
D) binary number
A) primitive variable
B) reference variable
C) numeric literal
D) binary number
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
43
Select all that apply. Which of the following are classes from the Java API?
A) Scanner
B) Random
C) Package
D) PrintWriter
A) Scanner
B) Random
C) Package
D) PrintWriter
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
44
Most of the programming languages used today are __________.
A) procedural
B) top-down
C) object-oriented
D) functional
A) procedural
B) top-down
C) object-oriented
D) functional
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
45
Overloading means that multiple methods in the same class __________.
A) have the same name but different return types
B) have different names but the same parameter list
C) have the same name but different parameter lists
D) perform the same function
A) have the same name but different return types
B) have different names but the same parameter list
C) have the same name but different parameter lists
D) perform the same function
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
46
The __________ package is automatically imported into all Java programs.
A) java.java
B) java.default
C) java.util
D) java.lang
A) java.java
B) java.default
C) java.util
D) java.lang
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
47
A UML diagram does not contain __________.
A) the class name
B) the method names
C) the field names
D) the object names
A) the class name
B) the method names
C) the field names
D) the object names
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
48
A constructor __________.
A) always accepts two arguments
B) has the return type of void
C) has the same name as the class
D) always has a private access specifier
A) always accepts two arguments
B) has the return type of void
C) has the same name as the class
D) always has a private access specifier
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
49
A(n) __________ can be thought of as a blueprint that can be used to create a type of __________.
A) object, class
B) class, object
C) cookie, cake
D) object, method
A) object, class
B) class, object
C) cookie, cake
D) object, method
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
50
The scope of a public instance field is __________.
A) only the class in which it is defined
B) inside the class but not inside any method
C) inside the parentheses of a method header
D) the instance methods and methods outside the class
A) only the class in which it is defined
B) inside the class but not inside any method
C) inside the parentheses of a method header
D) the instance methods and methods outside the class
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
51
Instance methods do not have the __________ key word in their headers.
A) public
B) static
C) private
D) protected
A) public
B) static
C) private
D) protected
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
52
Java allows you to create objects of the __________ class in the same way you would create primitive variables.
A) Random
B) String
C) PrintWriter
D) Scanner
A) Random
B) String
C) PrintWriter
D) Scanner
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
53
A reference variable stores a(n) __________.
A) binary encoded decimal
B) memory address
C) object
D) string
A) binary encoded decimal
B) memory address
C) object
D) string
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
54
Which of the following statements will create a reference, str, to the String "Hello, World"?
A) String str = "Hello, World";
B) string str = "Hello, World";
C) String str = new "Hello, World";
D) str = "Hello, World";
A) String str = "Hello, World";
B) string str = "Hello, World";
C) String str = new "Hello, World";
D) str = "Hello, World";
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
55
Given the following code, what will be the value of finalAmount when it is displayed?
public class Order
{
Private int orderNum;
Private double orderAmount;
Private double orderDiscount;
Public Order(int orderNumber, double orderAmt,
Double orderDisc)
{
OrderNum = orderNumber;
OrderAmount = orderAmt;
OrderDiscount = orderDisc;
}
Public int getOrderAmount()
{
Return orderAmount;
}
Public int getOrderDisc()
{
Return orderDisc;
}
}
Public class CustomerOrder
{
Public static void main(String[] args)
{
Int ordNum = 1234;
Double ordAmount = 580.00;
Double discountPer = .1;
Order order;
Double finalAmount = order.getOrderAmount() -
Order.getOrderAmount() * order.getOrderDisc();
System.out.printf("Final order amount = $%,.2f\n",
FinalAmount);
}
}
A) 528.00
B) 580.00
C) There is no value because the constructor has an error.
D) There is no value because the object, order, has not been created.
public class Order
{
Private int orderNum;
Private double orderAmount;
Private double orderDiscount;
Public Order(int orderNumber, double orderAmt,
Double orderDisc)
{
OrderNum = orderNumber;
OrderAmount = orderAmt;
OrderDiscount = orderDisc;
}
Public int getOrderAmount()
{
Return orderAmount;
}
Public int getOrderDisc()
{
Return orderDisc;
}
}
Public class CustomerOrder
{
Public static void main(String[] args)
{
Int ordNum = 1234;
Double ordAmount = 580.00;
Double discountPer = .1;
Order order;
Double finalAmount = order.getOrderAmount() -
Order.getOrderAmount() * order.getOrderDisc();
System.out.printf("Final order amount = $%,.2f\n",
FinalAmount);
}
}
A) 528.00
B) 580.00
C) There is no value because the constructor has an error.
D) There is no value because the object, order, has not been created.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
56
Given the following code, what will be the value of finalAmount when it is displayed?
public class Order
{
Private int orderNum;
Private double orderAmount;
Private double orderDiscount;
Public Order(int orderNumber, double orderAmt,
Double orderDisc)
{
OrderNum = orderNumber;
OrderAmount = orderAmt;
OrderDiscount = orderDisc;
}
Public double finalOrderTotal()
{
Return orderAmount - orderAmount * orderDiscount;
}
}
Public class CustomerOrder
{
Public static void main(String[ ] args)
{
Order order;
Int orderNumber = 1234;
Double orderAmt = 580.00;
Double orderDisc = .1;
Order = new Order(orderNumber, orderAmt, orderDisc);
Double finalAmount = order.finalOrderTotal();
System.out.printf("Final order amount = $%,.2f\n",
FinalAmount);
}
}
A) 528.00
B) 580.00
C) 522.00
D) There is no value because the object, order, has not been created.
public class Order
{
Private int orderNum;
Private double orderAmount;
Private double orderDiscount;
Public Order(int orderNumber, double orderAmt,
Double orderDisc)
{
OrderNum = orderNumber;
OrderAmount = orderAmt;
OrderDiscount = orderDisc;
}
Public double finalOrderTotal()
{
Return orderAmount - orderAmount * orderDiscount;
}
}
Public class CustomerOrder
{
Public static void main(String[ ] args)
{
Order order;
Int orderNumber = 1234;
Double orderAmt = 580.00;
Double orderDisc = .1;
Order = new Order(orderNumber, orderAmt, orderDisc);
Double finalAmount = order.finalOrderTotal();
System.out.printf("Final order amount = $%,.2f\n",
FinalAmount);
}
}
A) 528.00
B) 580.00
C) 522.00
D) There is no value because the object, order, has not been created.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
57
Two or more methods in a class may have the same name as long as __________.
A) they have different return types
B) they have different parameter lists
C) they have different return types but the same parameter list
D) You cannot have two methods with the same name.
A) they have different return types
B) they have different parameter lists
C) they have different return types but the same parameter list
D) You cannot have two methods with the same name.
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck
58
Methods that operate on an object's fields are called __________.
A) instance variables
B) instance methods
C) public methods
D) private methods
A) instance variables
B) instance methods
C) public methods
D) private methods
Unlock Deck
Unlock for access to all 58 flashcards in this deck.
Unlock Deck
k this deck