Deck 9: A Second Look at 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
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/40
Play
Full screen (f)
Deck 9: A Second Look at Classes and Objects
1
When a field is declared static,there will be
A) a copy of the field in each class object
B) only one copy of the field in memory
C) a copy of the field for each static method in the class
D) only two copies of the field in memory
A) a copy of the field in each class object
B) only one copy of the field in memory
C) a copy of the field for each static method in the class
D) only two copies of the field in memory
B
2
The term for the relationship created by object aggregation is
A) Has a
B) Is a
C) Sub-class object
D) Inner class
A) Has a
B) Is a
C) Sub-class object
D) Inner class
A
3
If the this variable is used to call a constructor,
A) a compiler error will result,if it is not the first statement of the constructor.
B) a compiler error will result,if it is the first statement of the constructor.
C) nothing will happen.
D) The this variable cannot be used as a constructor call.
A) a compiler error will result,if it is not the first statement of the constructor.
B) a compiler error will result,if it is the first statement of the constructor.
C) nothing will happen.
D) The this variable cannot be used as a constructor call.
A
4
When a method's return type is a class,what is actually returned to the calling program?
A) An object of that class
B) A reference to an object of that class
C) Only the values in the object that the method accessed
D) Nothing,the return type is strictly for documentation in this situation
A) An object of that class
B) A reference to an object of that class
C) Only the values in the object that the method accessed
D) Nothing,the return type is strictly for documentation in this situation
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
5
A deep copy of an object
A) is an assignment of that object to another object
B) is an operation that copies an aggregate object,and all the objects it references
C) is a bogus term,it has no meaning
D) is always a private method
A) is an assignment of that object to another object
B) is an operation that copies an aggregate object,and all the objects it references
C) is a bogus term,it has no meaning
D) is always a private method
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
6
If object1 and object2 are objects of the same class,to make object2 a copy of object1
A) assign object1 to object2,such as object2 = object1;
B) write a copy method that will make a field by field copy of object1 data members into object2 data members
C) use the Java copy method that is a part of the Java language
D) use the default constructor to create object2 with object1 data members
A) assign object1 to object2,such as object2 = object1;
B) write a copy method that will make a field by field copy of object1 data members into object2 data members
C) use the Java copy method that is a part of the Java language
D) use the default constructor to create object2 with object1 data members
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
7
If the following is from the method section of a UML diagram,which of the following statements is true? + equals(object2:Stock): boolean
A) This is a private method that receives two objects from the Stock class and returns a boolean value
B) This is a public method that accepts a Stock object as its argument and returns a boolean value
C) This is a private method that returns a boolean value
D) This is a public method that returns a Stock object
A) This is a private method that receives two objects from the Stock class and returns a boolean value
B) This is a public method that accepts a Stock object as its argument and returns a boolean value
C) This is a private method that returns a boolean value
D) This is a public method that returns a Stock object
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
8
A declaration for an enumerated type begins with this key word.
A) enumerated
B) enum_type
C) enum
D) ENUM
A) enumerated
B) enum_type
C) enum
D) ENUM
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
9
A static field is created by placing
A) the key word static after the field name
B) the key word static after the access specifier and before the field's data type
C) the key word static after the access specifier and field's data type
D) it in a static field block
A) the key word static after the field name
B) the key word static after the access specifier and before the field's data type
C) the key word static after the access specifier and field's data type
D) it in a static field block
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
10
Look at the following declaration. enum Tree { OAK,MAPLE,PINE }
What is the ordinal value of the MAPLE enum constant?
A) 0
B) 1
C) 2
D) 3
E) Tree.MAPLE
What is the ordinal value of the MAPLE enum constant?
A) 0
B) 1
C) 2
D) 3
E) Tree.MAPLE
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
11
If the following is from the method section of a UML diagram,which of the following statements is true? + add(object2:Stock): Stock
A) This is a private method named add that accepts and returns objects of the Stock class.
B) This is a private method named Stock that adds two objects.
C) This is a public method named add that accepts and returns references to objects in the Stock class.
D) This is a public method named Stock that adds two objects.
A) This is a private method named add that accepts and returns objects of the Stock class.
B) This is a private method named Stock that adds two objects.
C) This is a public method named add that accepts and returns references to objects in the Stock class.
D) This is a public method named Stock that adds two objects.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
12
What will be returned from a method,if the following is the method header: public Rectangle getRectangle()
A) An object of the class Rectangle
B) The address of an object of the class Rectangle
C) The values stored in the data members of the Rectangle object the method changed
D) A graph of a rectangle
A) An object of the class Rectangle
B) The address of an object of the class Rectangle
C) The values stored in the data members of the Rectangle object the method changed
D) A graph of a rectangle
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
13
The only limitation that static methods have is
A) they can refer to only non-static members of the class
B) they can only be called from static members of the class
C) they must be declared as public methods
D) they cannot refer to non-static members of the class
A) they can refer to only non-static members of the class
B) they can only be called from static members of the class
C) they must be declared as public methods
D) they cannot refer to non-static members of the class
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
14
If you have defined a class named SavingsAccount with a public static data member named numberOfAccounts,and created a SavingsAccount object referenced by the variable account20,which of the following will assign numberOfAccounts to numAccounts?
A) numAccounts = account20.numAccounts;
B) numAccounts = numberOfAccounts;
C) numAccounts = SavingsAccount.numberOfAccounts;
D) None of the above,you cannot reference a static data member.
A) numAccounts = account20.numAccounts;
B) numAccounts = numberOfAccounts;
C) numAccounts = SavingsAccount.numberOfAccounts;
D) None of the above,you cannot reference a static data member.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
15
Which of the following is not true about static methods?
A) It is necessary for an instance of the class to be created to execute the method.
B) They are created by placing the key word static after the access specifier in the method header.
C) They are called directly from the class.
D) They are often used to create utility classes that perform operations on data,but have no need to collect and store data.
A) It is necessary for an instance of the class to be created to execute the method.
B) They are created by placing the key word static after the access specifier in the method header.
C) They are called directly from the class.
D) They are often used to create utility classes that perform operations on data,but have no need to collect and store data.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
16
The whole-part relationship created by object aggregation is more often called
A) a has a relationship
B) an inner class relationship
C) an extra class relationship
D) an inside class relationship
A) a has a relationship
B) an inner class relationship
C) an extra class relationship
D) an inside class relationship
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
17
When the this variable is used to call a constructor,
A) it must be the first statement in the constructor making the call
B) it must be the last statement in the constructor making the call
C) it can be anywhere in the constructor making the call
D) You cannot use the this variable in a constructor call.
A) it must be the first statement in the constructor making the call
B) it must be the last statement in the constructor making the call
C) it can be anywhere in the constructor making the call
D) You cannot use the this variable in a constructor call.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
18
Look at the following declaration. enum Tree { OAK,MAPLE,PINE }
What is the fully-qualified name of the PINE enum constant?
A) PINE
B) enum.PINE
C) Tree.PINE
D) enum.PINE
E) PINE.Tree
What is the fully-qualified name of the PINE enum constant?
A) PINE
B) enum.PINE
C) Tree.PINE
D) enum.PINE
E) PINE.Tree
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
19
If you have defined a class SavingsAccount with a public static method getNumberOfAccounts(),and created a SavingsAccount object referenced by the variable account20,which of the following will call the getNumberOfAccounts()method?
A) getNumberOfAccounts();
B) SavingsAccount.getNumberOfAccounts();
C) getNumberOfAccounts(account20);
D) None of the above,you cannot call a static method.
A) getNumberOfAccounts();
B) SavingsAccount.getNumberOfAccounts();
C) getNumberOfAccounts(account20);
D) None of the above,you cannot call a static method.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
20
Which of the following is not true about static methods?
A) It is not necessary for an instance of the class to be created to execute the method.
B) They are created by placing the key word static after the access specifier in the method header.
C) They are called from an instance of the class.
D) They are often used to create utility classes that perform operations on data,but have no need to collect and store data.
A) It is not necessary for an instance of the class to be created to execute the method.
B) They are created by placing the key word static after the access specifier in the method header.
C) They are called from an instance of the class.
D) They are often used to create utility classes that perform operations on data,but have no need to collect and store data.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
21
If you write a toString method for a class,Java will automatically call the method any time you concatenate an object of the class with a string.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
22
The names of the enum constants in an enumerated data type must be enclosed in quotation marks.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
23
Enumerated types have this method,which returns the position of an enum constant in the declaration list.
A) toString
B) position
C) ordinal
D) location
A) toString
B) position
C) ordinal
D) location
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
24
The JVM periodically performs this process to remove unreferenced objects from memory.
A) memory sweeping
B) garbage collection
C) memory shuffling
D) system restore
A) memory sweeping
B) garbage collection
C) memory shuffling
D) system restore
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
25
CRC stands for
A) Code,Reuse,Constancy
B) Class,Responsibilities,Collaborations
C) Class,Redundancy,Collections
D) Class,Recyclability,Collaborations
A) Code,Reuse,Constancy
B) Class,Responsibilities,Collaborations
C) Class,Redundancy,Collections
D) Class,Recyclability,Collaborations
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
26
You can declare an enumerated data type inside of a method.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
27
An enumerated data type is actually a special type of class.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
28
If you write a toString method to display the contents of an object,object1,for a class,Class1,then the following two statements are equivalent:
System.out.println(object1);
System.out.println(object1.toString());
System.out.println(object1);
System.out.println(object1.toString());
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
29
Assume the class BankAccount has been created,and the following statement correctly creates an instance of the class: BankAccount account = new BankAccount(5000.0);
What is true about the following statement?
System.out.println(account);
A) The method will display unreadable binary data on the screen.
B) A compiler error will occur.
C) The account object's toString method will be implicitly called.
D) A runtime error will occur.
What is true about the following statement?
System.out.println(account);
A) The method will display unreadable binary data on the screen.
B) A compiler error will occur.
C) The account object's toString method will be implicitly called.
D) A runtime error will occur.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
30
Assuming the following declaration exists: enum Tree { OAK,MAPLE,PINE }
What will the following code display?
System.out.println(Tree.OAK);
A) Tree.OAK
B) 0
C) 1
D) OAK
E) Nothing.This statement will cause an error.
What will the following code display?
System.out.println(Tree.OAK);
A) Tree.OAK
B) 0
C) 1
D) OAK
E) Nothing.This statement will cause an error.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
31
The this key word is the name of a reference variable that is available to all static methods.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
32
When an object reference is passed to a method,the method may change the values in the object.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
33
If a class has a method named finalize,it is called automatically just before a data member that has been identified as final of the class is destroyed by the garbage collector.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
34
An instance of a class does not have to exist in order for values to be stored in a class's static fields.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
35
A class's static methods do not operate on the fields that belong to any instance of the class.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
36
If a class has a method named finalize,it is called automatically just before an instance of the class is destroyed by the garbage collector.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
37
The key word this is the name of a reference variable that an object can use to refer to itself.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
38
When an object is passed as an argument,it is actually a reference to the object that is passed.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
39
You cannot use the fully-qualifed name of an enum constant for this.
A) a switch expression
B) an argument to a method
C) a case expression
D) all of these
A) a switch expression
B) an argument to a method
C) a case expression
D) all of these
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck
40
Enum constants have a toString method.
Unlock Deck
Unlock for access to all 40 flashcards in this deck.
Unlock Deck
k this deck