Unit 3 Flashcards

1
Q
  1. What is an association in object-oriented programming?
    • a) A collection of classes needed for a database
    • b) A generalization relationship between two objects
    • c) A link between two classes that allows them to communicate through their instances
    • d) A dependency relationship required for program compilation
A

Correct Answer: c) A link between two classes that allows them to communicate through their instances

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  1. In the context of Java, what does aggregation represent?
    • a) A dynamic method dispatch mechanism
    • b) A whole-part relationship between objects
    • c) An array of objects stored within another object
    • d) A static class method that operates on global data
A

Correct Answer: b) A whole-part relationship between objects

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  1. How is a composition relationship different from aggregation?
    • a) Composition implies a weaker relationship where the lifecycle of the parts is not managed by the whole.
    • b) In composition, objects can exist independently of the whole, whereas in aggregation they cannot.
    • c) Composition implies a stronger relationship where the parts do not exist independently of the whole.
    • d) There is no practical difference in code, only theoretical.
A

Correct Answer: c) Composition implies a stronger relationship where the parts do not exist independently of the whole.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. What does it mean if a class A has a unidirectional association with class B in Java?
    • a) Class A can contain and control instances of Class B, but not vice versa.
    • b) Class B can contain and control instances of Class A, but not vice versa.
    • c) Instances of Class A can call methods on instances of Class B only.
    • d) Both classes can contain each other.
A

Correct Answer: c) Instances of Class A can call methods on instances of Class B only.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  1. In a UML diagram, how is a bidirectional association represented compared to a unidirectional association?
    • a) Bidirectional is shown with a line having arrowheads on both ends, whereas unidirectional has only one.
    • b) Unidirectional is shown with a dotted line, while bidirectional uses a solid line.
    • c) Unidirectional associations are not represented in UML.
    • d) Bidirectional is shown with a single arrow; unidirectional uses a line without arrows.
A

Correct Answer: a) Bidirectional is shown with a line having arrowheads on both ends, whereas unidirectional has only one.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  1. What is multiplicity in the context of associations in UML diagrams?
    • a) It specifies the abstract classes involved in the association.
    • b) It specifies the number of instances of one class that can be associated with one instance of another class.
    • c) It determines the methods that can be called on the associated objects.
    • d) It indicates the maximum number of methods that can be invoked.
A

Correct Answer: b) It specifies the number of instances of one class that can be associated with one instance of another class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  1. How would you implement a “1 to many” relationship in Java code?
    • a) By using a single instance variable of type List in the class on the “1” side.
    • b) By creating an array of objects on the “many” side.
    • c) By declaring static variables in both classes.
    • d) By using a HashMap to manage multiple instances with unique keys.
A

Correct Answer: a) By using a single instance variable of type List in the class on the “1” side.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. What is a wrapper class in Java?
    • a) A class that contains static methods to operate on primitives.
    • b) A class that ‘wraps’ primitive types in an object so they can be included in activities reserved for objects.
    • c) Any class that implements the Serializable interface.
    • d) A class that serves to combine several classes into one compound class.
A

Correct Answer: b) A class that ‘wraps’ primitive types in an object so they can be included in activities reserved for objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  1. Which of the following best describes the role of the Integer class in Java?
    • a) To provide a way to use int values as method parameters where Objects are expected.
    • b) To extend the functionality of the int data type.
    • c) To encapsulate the complexity of number management in Java.
    • d) To serve as the default type for integer values in Java.
A

Correct Answer: a) To provide a way to use int values as method parameters where Objects are expected.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
  1. When are objects of wrapper classes, like Integer and Double, necessary?
    • a) When there’s a need to store primitive data types in parameterized classes, such as ArrayList.
    • b) When the program requires explicit casting between different object types.
    • c) When large numbers of primitive types would cause memory overflow without wrappers.
    • d) When the primitives need to be converted to objects for serialization.
A

Correct Answer: a) When there’s a need to store primitive data types in parameterized classes, such as ArrayList.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly