# Review Exercises (Set C2)

For questions #1-13 below, refer to the following code.
1. What is printed when line A is executed?

2. What is printed when line B is executed?

3. What is printed when line C is executed?

4. What is printed when line D is executed?

5.
1. Assuming all of the classes are defined in the same package, what visibility modifiers can be used in place of public when the name_ and idNum_ instance variables of the Person class are declared, without causing an error? (Note: they are accessed directly in the FacultyMember class)

2. Rather than using “public” or one of the modifiers mentioned in your answer to (a), what would be a better route to take to maximize the programmer's ability to modify the instance variables of this code in the future (without affecting any other code that might be dependent on this class)?

6. What is printed when line E is executed?

7. What is printed when lines F and G are executed (in order)?

8. What could the word "Person" be replaced with in line H so that the three following lines do not create an error.

9. What is printed when line I is executed?

10. Which, if any, of the two lines J and K would produce an error if they were both uncommented? If either produces an error, describe it.

11. Is it possible to create a subclass of StudentTutor that is abstract?

12. If "public abstract String greeting();" was removed from the Person class, would an error be generated? If yes, describe it.

13. The Person class is a subclass of what class?

14. Describe the difference between overloaded methods and overridden methods.

15. What symbol and/or text format is used to indicate a static method is protected in UML?

16. MouseListener, ActionListener, and KeyListener are all examples of which of the following (circle all that apply)

1. Classes
2. Interfaces
3. Packages
4. Methods
17. Circle all of the following statements that are true. (There may or may not be more than one.)

1. A final method is a method that can't be overridden
2. A final class is a class that contains only final methods
3. A class may implement multiple interfaces
4. An abstract class may be extended by more than one class

1.

A person with a given name and id created
A student named Bob Wu was created
A student tutor was created

2.

person 102 named Bob Wu who is also a sophomore, and is a tutor in math

3.

A John Doe was created
A student was created.

4.

person 102 named Bob Wu who is also a sophomore, and is a tutor in math

5.

1. The protected modifier and the default modifier (i.e., no modifier) can both be used.

2. Make the instance variables private and use getters and setters to access or change their values.

6.

A John Doe was created
A faculty member with name John Doe was created.

7.

true
false

8. Object

9.

I am a ...
person
student
student tutor

10. Lines J and K do not produce any errors

11. yes

12. No syntax error is produced. If the PeopleTester class is executed, no run-time error is produced. The only effect would be that if an AvailableToHelp reference was used to reference a FacultyMember object, one could no longer invoke the greeting() method without casting first to a FacultyMember.

13. Object

14. A method has been "overloaded" when the same name is used to define two (or more) methods, but each method has a different method signature (i.e., the input parameter(s) for each method are different). Overloaded methods can appear either in the same class, or across a class and one of its subclasses. A method has been "overridden", on the other hand, when it is defined in both a class and some subclass of that class, with an identical method signature (i.e., same name AND same input parameters), except these two methods do different things.

15. A prefix of # indicates the method is protected, and the method name is underlined to indicate it is static.

16. b.

17. a,c,d