1
Working with Java
Classes
2
Objectives
At the end of the lesson, the student should be able to:
● Explain object-oriented programming and some of its
concepts
● Differentiate between classes and objects
● Differentiate between instance variables/methods and
class(static) variables/methods
● Explain what methods are and how to call and pass
parameters to methods
●
Identify the scope of a variable
● Cast primitive data types and objects
● Compare objects and determine the class of an objects
3
Brief Introduction
on OOP
4
Introduction to OOP
● Object-Oriented programming or OOP
– Revolves around the concept of objects as the basic elements
of your programs.
– These objects are characterized by their properties and
behaviors.
5
Introduction to OOP
● Example of objects
objects in the physical world can easily be modeled as
software objects using the properties as data and the
behaviors as methods
6
Encapsulation
● Encapsulation
– The scheme of hiding implementation details of a class.
– The caller of the class does not need to know the
implementation details of a class
– The implementation can change without affecting the caller of
the class
7
Classes and
Objects (Object
Instances)
8
Classes and Objects
● Class
– can be thought of as a template, a prototype or a blueprint of an
object
–
is the fundamental structure in object-oriented programming
● Two types of class members:
– Fields (properties, variables)
● specify the data types defined by the class
– Methods (behavior)
● specify the operations
9
Classes and Objects
● Object
– An object is an instance of a class - we will call it object instance
– The property values of an object instance is different from the
ones of other object instances of a same class
– Object instances of a same class share the same behavior
(methods)
10
Classes and Objects
● To differentiate between classes and objects, let us
discuss an example:
11
Classes and Objects
● Classes provide the benefit of reusability.
● Software programmers can use a