Chapter 4
Writing Classes
– Part 1
Java Software Solutions
Foundations of Program Design
9th Edition
John Lewis
William Loftus
Key Concept
• The heart of object-oriented
programming is defining
classes that represent
objects with well-defined
state and behavior.
Key Concept
• The scope of a variable,
which determines where it
can be referenced, depends
on where it is declared.
Key Concept
• A UML class diagram helps
us visualize the contents of
and relationships among the
classes of a program.
Key Concept
An object should be
encapsulated, guarding its data
from inappropriate access.
Key Concept
Instance variables should be
declared with private visibility
to promote encapsulation.
Key Concept
• Most objects contain
accessor and mutator
methods to allow the client
to manage data in a
controlled manner.
Key Concept
The value returned from a
method must be consistent
with the return type in the
method header.
Key Concept
When a method is called, the
actual parameters are copied
into the formal parameters.
Key Concept
A variable declared in a
method is local to that method
and cannot be used outside of
it.
Key Concept
A constructor cannot have any
return type, even void.
Writing
Classes
• We've been using predefined classes from
the Java API. Now we will learn to write our
own classes.
• Chapter 4 focuses on:
• class definitions
• instance data
• encapsulation and Java modifiers
• method declaration and parameter passing
• constructors

Java Chapter 04 - Writing Classes: part 1

  • 1.
    Chapter 4 Writing Classes –Part 1 Java Software Solutions Foundations of Program Design 9th Edition John Lewis William Loftus
  • 2.
    Key Concept • Theheart of object-oriented programming is defining classes that represent objects with well-defined state and behavior.
  • 3.
    Key Concept • Thescope of a variable, which determines where it can be referenced, depends on where it is declared.
  • 4.
    Key Concept • AUML class diagram helps us visualize the contents of and relationships among the classes of a program.
  • 5.
    Key Concept An objectshould be encapsulated, guarding its data from inappropriate access.
  • 6.
    Key Concept Instance variablesshould be declared with private visibility to promote encapsulation.
  • 7.
    Key Concept • Mostobjects contain accessor and mutator methods to allow the client to manage data in a controlled manner.
  • 8.
    Key Concept The valuereturned from a method must be consistent with the return type in the method header.
  • 9.
    Key Concept When amethod is called, the actual parameters are copied into the formal parameters.
  • 10.
    Key Concept A variabledeclared in a method is local to that method and cannot be used outside of it.
  • 11.
    Key Concept A constructorcannot have any return type, even void.
  • 12.
    Writing Classes • We've beenusing predefined classes from the Java API. Now we will learn to write our own classes. • Chapter 4 focuses on: • class definitions • instance data • encapsulation and Java modifiers • method declaration and parameter passing • constructors