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
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/49
Play
Full screen (f)
Deck 6: A First Look at Classes
1
This refers to the combining of data and code into a single object.
A) Data hiding
B) Abstraction
C) Object
D) Encapsulation
A) Data hiding
B) Abstraction
C) Object
D) Encapsulation
D
2
It is common practice in object-oriented programming to make all of a class's
A) methods private
B) fields private
C) fields public
D) fields and methods public
A) methods private
B) fields private
C) fields public
D) fields and methods public
B
3
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
C
4
In your textbook the general layout of a UML diagram is a box that is divided into three sections.The top section has the _______;the middle section holds _______;the bottom section holds _______.
A) class name;attributes or fields;methods
B) class name;object name;methods
C) object name;attributes or fields;methods
D) object name;methods;attributes or fields
A) class name;attributes or fields;methods
B) class name;object name;methods
C) object name;attributes or fields;methods
D) object name;methods;attributes or fields
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
5
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 49 flashcards in this deck.
Unlock Deck
k this deck
6
You should not define a class field that is dependent upon the values of other class fields...
A) in order to avoid having stale data
B) because it is redundant
C) because it should be defined in another class
D) in order to keep it current
A) in order to avoid having stale data
B) because it is redundant
C) because it should be defined in another class
D) in order to keep it current
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
7
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 49 flashcards in this deck.
Unlock Deck
k this deck
8
Class objects normally have __________ that perform useful operations on their data,but primitive variables do not.
A) fields
B) instances
C) methods
D) relationships
A) fields
B) instances
C) methods
D) relationships
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
9
For the following code,which statement is not true? public class Circle
{
Private double radius;
Public double x;
Private double y;
}
A) x is available to code that is written outside the Circle class.
B) radius is not available to code written outside the Circle class.
C) radius,x,and y are called members of the Circle class.
D) y is available to code that is written outside the Circle class.
{
Private double radius;
Public double x;
Private double y;
}
A) x is available to code that is written outside the Circle class.
B) radius is not available to code written outside the Circle class.
C) radius,x,and y are called members of the Circle class.
D) y is available to code that is written outside the Circle class.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
10
A UML diagram does not contain
A) the class name.
B) the method names.
C) the field names.
D) object names
A) the class name.
B) the method names.
C) the field names.
D) object names
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
11
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 definition
D) using the private access specifier on the class fields
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 definition
D) using the private access specifier on the class fields
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
12
In the cookie cutter metaphor,think of the ________ as a cookie cutter and ________ as the cookies.
A) object;classes
B) class;objects
C) class;fields
D) attribute;methods
A) object;classes
B) class;objects
C) class;fields
D) attribute;methods
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
13
Another term for an object of a class is
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 49 flashcards in this deck.
Unlock Deck
k this deck
14
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 49 flashcards in this deck.
Unlock Deck
k this deck
15
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) x is available to code that is written outside the Circle class.
B) radius is not available to code written outside the Circle class.
C) radius,x,y,and z are called members of the Circle class.
D) z is available to code that is written outside the Circle class.
{
Private double radius;
Public double x;
Private double y;
Private double z;
}
A) x is available to code that is written outside the Circle class.
B) radius is not available to code written outside the Circle class.
C) radius,x,y,and z are called members of the Circle class.
D) z is available to code that is written outside the Circle class.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
16
What does the following UML diagram entry mean? + setHeight(h : double): void
A) this is a public attribute named Height and is a double data type
B) this is a private method with no parameters and returns a double data type
C) this is a private attribute named Height and is a double data type
D) this is a public method with a parameter of data type double and does not return a value
A) this is a public attribute named Height and is a double data type
B) this is a private method with no parameters and returns a double data type
C) this is a private attribute named Height and is a double data type
D) this is a public method with a parameter of data type double and does not return a value
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
17
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
C) inside the parentheses of a method header
D) the method in which they are defined
A) the instance methods of the same class
B) inside the class,but not inside any method
C) inside the parentheses of a method header
D) the method in which they are defined
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
18
A constructor
A) always accepts two arguments
B) has return type of void
C) has the same name as the class
D) always has an access specifier of private
A) always accepts two arguments
B) has return type of void
C) has the same name as the class
D) always has an access specifier of private
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
19
One or more objects may be created from a(n)
A) field
B) class
C) method
D) instance
A) field
B) class
C) method
D) instance
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
20
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.println("Final order amount = $" +
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.
{
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.println("Final order amount = $" +
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 49 flashcards in this deck.
Unlock Deck
k this deck
21
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 49 flashcards in this deck.
Unlock Deck
k this deck
22
Which of the following is not involved in finding the classes when developing an object-oriented application?
A) Describe the problem domain.
B) Identify all the nouns.
C) Write the code.
D) Refine the list of nouns to include only those that are relevant to the problem.
A) Describe the problem domain.
B) Identify all the nouns.
C) Write the code.
D) Refine the list of nouns to include only those that are relevant to the problem.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
23
Look at the following statement. import java.util.Scanner;
This is an example of
A) a wildcard import
B) an explicit import
C) unconditional import
D) conditional import
This is an example of
A) a wildcard import
B) an explicit import
C) unconditional import
D) conditional import
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
24
In UML diagrams,this symbol indicates that a member is public.
A) /
B) @
C) -
D) +
A) /
B) @
C) -
D) +
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
25
After the header,the body of the method appears inside a set of
A) brackets,[]
B) paretheses, ()
C) braces,{}
D) double quotes,""
A) brackets,[]
B) paretheses, ()
C) braces,{}
D) double quotes,""
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
26
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 49 flashcards in this deck.
Unlock Deck
k this deck
27
In a UML diagram to indicate the data type of a variable 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 49 flashcards in this deck.
Unlock Deck
k this deck
28
A constructor is a method that
A) returns an object of the class.
B) never receives any arguments.
C) with the name ClassName.constructor.
D) performs initialization or setup operations.
A) returns an object of the class.
B) never receives any arguments.
C) with the name ClassName.constructor.
D) performs initialization or setup operations.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
29
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.println("Final order amount = $" +
FinalAmount);
}
}
A) 528.00
B) 580.00
C) 522.00
D) There is no value because the object order has not been created.
{
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.println("Final order amount = $" +
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 49 flashcards in this deck.
Unlock Deck
k this deck
30
When an object is created,the attributes associated with the object are called
A) instance fields
B) instance methods
C) fixed attributes
D) class instances
A) instance fields
B) instance methods
C) fixed attributes
D) class instances
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
31
A class's responsibilities include
A) the things a class is responsible for doing
B) the things a class is responsible for knowing
C) both A and B
D) neither A or B
A) the things a class is responsible for doing
B) the things a class is responsible for knowing
C) both A and B
D) neither A or B
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
32
Quite often you have to use this statement to make a group of classes available to a program.
A) import
B) use
C) link
D) assume
A) import
B) use
C) link
D) assume
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
33
Look at the following statement. import java.util.*;
This is an example of
A) a wildcard import
B) an explicit import
C) unconditional import
D) conditional import
This is an example of
A) a wildcard import
B) an explicit import
C) unconditional import
D) conditional import
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
34
Overloading means 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 49 flashcards in this deck.
Unlock Deck
k this deck
35
An access specifier indicates how the class may be accessed.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
36
The following 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 49 flashcards in this deck.
Unlock Deck
k this deck
37
This is a group of related classes.
A) archive
B) package
C) collection
D) attachment
A) archive
B) package
C) collection
D) attachment
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
38
In UML diagrams,this symbol indicates that a member is private .
A) *
B) #
C) -
D) +
A) *
B) #
C) -
D) +
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
39
Which of the following statements will create a reference,str,to the string,"Hello,world"? (1)String str = new String("Hello,world");
(2)String str = "Hello,world";
A) 1
B) 2
C) 1 and 2
D) Neither 1 or 2
(2)String str = "Hello,world";
A) 1
B) 2
C) 1 and 2
D) Neither 1 or 2
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
40
Instance methods should be declared static.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
41
A constructor is a method that is automatically called when an object is created.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
42
Instance methods do not have the key word static in their headers.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
43
A method that gets a value from a class's field but does not change it is known as a mutator method.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
44
The java.lang package is automatically imported into all Java programs.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
45
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 49 flashcards in this deck.
Unlock Deck
k this deck
46
True/False: The term "no-arg constructor" is applied to any constructor that does not accept arguments.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
47
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 49 flashcards in this deck.
Unlock Deck
k this deck
48
The term "default constructor" is applied to the first constructor written by the author of a class.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck
49
The public access specifier for a field indicates that the attribute may not be accessed by statements outside the class.
Unlock Deck
Unlock for access to all 49 flashcards in this deck.
Unlock Deck
k this deck