Chapter 4: Objects Revisited

Chapter 4 – Writing Classes

Concepts to discuss:
keyconcept2

  • attributes, states and instance fields
  • behavior and methods

attributesAndMethods1

methodofaclass4

rollingdiceUML5

keyconcept4

  • object variable and object reference
  • classes as blueprints
  • members of a class

memberofaclass3

 

  • constructors

keyconcept11

 

  • methods

flowofcontrol9

methoddeclaration8

keyconcept8

returnmethod10

keyconcept9

passingpara11

  • access specifiers or visibility modifiers

effectofpublicprivatevisibility7

  • 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.

keyconcept6

 

  • variable scope

keyconcept3

keyconcept10

 

  • ENCAPSULATION

keyconcept5

 

aclientinteraction6

keyconcept7

Answer the following questions:
Lesson Questions

  1. What is an attribute?
  2. What is an operation?
  3. List some attributes and operations that might be defined for a class called Book that represents a book in a library.
  4. 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.
  5. What is the difference between an object and a class?
  6. What is the scope of a variable?
  7. What are UML diagrams designed to do?
  8. Objects should be self-governing. Explain.
  9. What is a modifier?
  10. Describe each of the following:
    ◗ public method
    ◗ private method
    ◗ public variable
    ◗ private variable
  11. What does the return statement do?
  12. Explain the difference between an actual parameter and a formal parameter.
  13. What are constructors used for? How are they defined?
  14. How are overloaded methods distinguished from each other?
  15. What is method decomposition?
  16. Explain how a class can have an association with itself.
  17. 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.