Вы находитесь на странице: 1из 13

Object Oriented

Programming Concepts
Objectives:
Learn to explain the following terms
Object
Class
Inheritance
Interface
Package

KEN Education Object Oriented Programming Concepts / Slide 1 of 13


Object Oriented Programming
Concepts
What is an Object (contd.)
The Real World is composed of objects.

Objects have state and behaviour.

The concept of Real World Objects is translated


to Object Oriented Programming.

Software objects are similar to Real World


objects.
KEN Education Object Oriented Programming Concepts / Slide 2 of 13
Object Oriented Programming
Concepts
What is an Object (Contd.)

An object stores state


in fields or variables and
behaviour is exposed thru
methods.

A software Object

KEN Education Object Oriented Programming Concepts / Slide 3 of 13


Object Oriented Programming
Concepts
What is a Class
A class is a blueprint from which objects are
created.

Bicycle as a Software Object

KEN Education Object Oriented Programming Concepts / Slide 4 of 13


Object Oriented Programming
Concepts

Demo Example With Bicycle Class

KEN Education Object Oriented Programming Concepts / Slide 5 of 13


Object Oriented Programming
Concepts
What is Inheritance
Different objects have something in common with each other.

In OOP, classes can inherit commonly used state and behaviour from other classes.

In Java a class is allowed to have one direct superclass and each superclass can have unlimited number of subclasses.

KEN Education Object Oriented Programming Concepts / Slide 6 of 13


Object Oriented Programming
Concepts

A Hierarchy of Bicycle Classes

KEN Education Object Oriented Programming Concepts / Slide 7 of 13


Object Oriented Programming
Concepts
What is an Interface
To create a subclass at the beginning of the class declaration use the extends keyword followed by the name of the class to inherit from.

class MountainBike extends Bicycle {


// new fields and methods of
// mountain bike. All fields and
// methods of bicycle are present.
}

KEN Education Object Oriented Programming Concepts / Slide 8 of 13


Object Oriented Programming
Concepts
What is an Interface
Methods form the interface between an
object and the outside world.
An interface is a group of methods
with empty bodies.
interface Bicycle {
void changeCadence(int newValue);
void changeGear(int newValue);
void speedUp(int increment);
void applyBrakes(int decrement);
}

KEN Education Object Oriented Programming Concepts / Slide 9 of 13


Object Oriented Programming
Concepts

What is an Interface
To implement the interface use the
implements keyword in the class declaration.

class ACMEBicycle implements Bicycle


{
//remainder of this class
//implemented as before
}

KEN Education Object Oriented Programming Concepts / Slide 10 of 13


Object Oriented Programming
Concepts

What is an Interface (Contd.)


If a class claims to implement an Interface
then all the methods from the Interface must
appear in the class before it will compile.

KEN Education Object Oriented Programming Concepts / Slide 11 of 13


The Hello World Application
What is a Package

A Package is a namespace that can be used


to organize related Classes and Interfaces.
A Package is similar to the use of Folders in a
computer.
The Java Platform has an enormous set of
Class Libraries organized into several Packages.
These are commonly known as an API.

KEN Education Object Oriented Programming Concepts / Slide 12 of 13


Summary
Summary
Objects have state and behaviour. State is
maintained in fields and behaviour is implemented
by coding methods.
A Class is a blueprint from which objects are
created.
Inheritance can be carried out using the extends
Keyword. Java allows only one superclass.
An Interface is a group of methods with empty
bodies.
A package is collection of Classes and Interfaces.

KEN Education Object Oriented Programming Concepts / Slide 13 of 13

Вам также может понравиться