Chapter 4 – Writing Classes
Concepts to discuss:
- attributes, states and instance fields
- behavior and methods
- object variable and object reference
- classes as blueprints
- members of a class
- constructors
- methods
- access specifiers or visibility modifiers
- What does a predicate method do? It evaluates the predicate on the value passed to this function as the argument and then returns a boolean value.
- variable scope
- ENCAPSULATION
Answer the following questions:
Lesson Questions
- What is an attribute?
- What is an operation?
- List some attributes and operations that might be defined for a class called Book that represents a book in a library.
- True or False? Explain.
a. We should use only classes from the Java standard class library when writing our programs—there is no need to define or use other classes.
b. An operation on an object can change the state of an object.
c. The current state of an object can affect the result of an operation on that object.
d. In Java, the state of an object is represented by its methods. - What is the difference between an object and a class?
- What is the scope of a variable?
- What are UML diagrams designed to do?
- Objects should be self-governing. Explain.
- What is a modifier?
- Describe each of the following:
◗ public method
◗ private method
◗ public variable
◗ private variable - What does the return statement do?
- Explain the difference between an actual parameter and a formal parameter.
- What are constructors used for? How are they defined?
- How are overloaded methods distinguished from each other?
- What is method decomposition?
- Explain how a class can have an association with itself.
- What is an aggregate object?
Submit your answers as we discuss them. This assignment will take more than one lesson but submit what you have every time we have the lesson.