SE 450: Midterm Exam – Winter 2021
SE 450: Midterm Exam – Winter 2021
1. An instance variable belongs to the class in which it is declared.
ANSWER:
2. A constructor is a method that never returns anything, in fact it has void return type.
ANSWER:
3. A constructor is called the “default constructor” , if it has no parameters.
ANSWER:
4. A constructor is a method and therefore can be used through the dot operator, applied to
an instance of the class where it was declared.
ANSWER:
5. The following variable x is correctly used:
Point p1 = new Point ();
Point.x = 10;
ANSWER:
6. If a method is declared static, it cannot be called outside of its package.
ANSWER:
7. If we don’t prefix modifiers to a method, the method is only accessible within the same
package.
ANSWER:
8. An instance initializer is invoked before constructors.
ANSWER:
9. The keyword this allows you to reference the members of an object that will be created
only at runtime within the object itself.
SE 450: Midterm Exam – Winter 2021
Explain briefly the difference between these two elements of a UML class diagram: “aggregation” and “composition”. Provide also an example of ONE small UML class diagram including
all aggregation, composition and generalization relationships. Do not use any examples from the
lecture slides.
Create a City class that abstracts the concept of city(not an abstract class). Then declare a
Nation class declaring a capital instance variable of type City. Finally, create an Question2Main
class that creates a nation with a capital, and prints a sentence that verifies the actual association
between the nation and the capital. Create constructors for these classes. Some possible attributes
for Nation class can be name, capital, and population.
DETAILED ASSIGNMENT
20210205005800midterm_exam_winter2021_fillable_protected
password is se450winter2021.