0% found this document useful (0 votes)
62 views11 pages

Object Oriented Programming

1. The document discusses object-oriented programming concepts including classes, objects, attributes, and behaviors. 2. A class defines common attributes and behaviors for a group of objects. Attributes describe an object's state while behaviors are actions the object can perform. 3. The document provides examples of classes like BankAccount and UniversityStudent to demonstrate how classes define common attributes like name and balance that individual objects then contain specific values for.

Uploaded by

Joseph Josef
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
62 views11 pages

Object Oriented Programming

1. The document discusses object-oriented programming concepts including classes, objects, attributes, and behaviors. 2. A class defines common attributes and behaviors for a group of objects. Attributes describe an object's state while behaviors are actions the object can perform. 3. The document provides examples of classes like BankAccount and UniversityStudent to demonstrate how classes define common attributes like name and balance that individual objects then contain specific values for.

Uploaded by

Joseph Josef
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 11

1

Lecture 2: Object-Oriented Programming


(OOP)
CSC 1214: Object-Oriented Programming
3
Outline
Object-Oriented Programming:
Objects and Classes
Attributes and Behaviors
Creating a Class
5
Object-Oriented Programming:
Classes and Objects
Class
A class is a template used to create an object. Every object created
from the same class has similar features.
A class is a blueprint of an object.
Think of a class as a plan for a house. Before you build a house, you
should have a plan. Once you have a plan, however, you can build
any number of houses that follow that plan.
Object
An object is an instance of a class.
An object has state i.e., descriptive characteristics
An object has behaviours i.e., what it can do (what can be done to it)
In an object-oriented programming language you use classes
and objects to organize your program and data.
5
Object-Oriented Programming:
Classes and Objects
A Class
(the Concept)
Johns Bank Account
Balance: 5,257.51/=
Objects
(three Instances of the concept)
Otims Bank Account
Balance: 1,245,069.89/=
Marys Bank Account
Balance: 16,833.27/=
Multiple objects
of the same class
BankAccount
- balance: double
+ getBalance()
+ deposit(double amount)
+ withdraw(double amount)
Attributes
(State)
Methods
(Behavior)
6
Object-Oriented Programming:
Attributes and Behavior
A class for representing a university student could have
the following attributes (state):
Name
Student No
Course
In a class, attributes are defined by variablesplaces to
store information in a computer program. Instance
variables are attributes that have values that differ from
one object to another.
8
Object-Oriented Programming:
Attributes and Behavior
An instance variable defines an attribute of one particular
object. The objects class defines what kind of attribute it
is, and each instance stores its own value for that
attribute. Instance variables also are called object
variables.
The following defines an instance variable of a university
student:
Name: Mary
Age: 20
Student No: 204000596
Course: Computer Science
For example, the UniversityStudent class defines an age
instance variable. This must be an instance variable
because each student has a different age. The value of a
students age instance variable could be changed to as
year in-out.
9
Object-Oriented Programming:
Attributes and Behavior
Behavior of a Class of Objects - Behavior refers to the things
that a class of objects can do to themselves and other objects.
Behavior can be used to change the attributes of an object,
receive information from other objects, and send messages to
other objects asking them to perform tasks.
A UniversityStudent class could have the following behavior:
Attend classes
Seat for tests
Submit assignments
Pay university fees
Communication
Behavior for a class of objects is implemented using methods.
10
Object-Oriented Programming:
Attributes and Behavior
Methods are groups of related statements in a class that
perform a specific task.
Objects communicate with each other using methods. A
class or an object can call methods in another class or
object for many reasons, including the following:
To report a change to another object
To tell the other object to change something about
itself
To ask another object to do something
For example, two students could use methods to ask
a fellow student to discuss an assignment between
them and even submit in group if need be, and a
student could ask another to take him/her for lunch/
dinner.
12
More Examples of Classes and Objects
13
More Examples of Classes and Objects
Class : Cat
!""#$%&"'()
Cat name
Habitat
Weight
Diet
Physical appearance

Operations:
Hunt
type of noise
Tiger
Lion
Cheetah
African-golden
14
OOP in Java
The biggest challenge for a new Java programmer is
learning object-oriented programming at the same time
the Java language.
The identification of classes and objects is the hardest
part of object-oriented design.
One simple technique for identifying classes is to write a
description of the problem, list all the nouns (attributes)
that appear in the description, and then choose your
possible classes from the list.
Classification means that objects with the same data
structure (attributes) and behavior (operations) are
grouped into a class.

You might also like