Presentation is loading. Please wait.

Presentation is loading. Please wait.

Object-Oriented Programming

Similar presentations


Presentation on theme: "Object-Oriented Programming"— Presentation transcript:

1 Object-Oriented Programming
Our world consists of objects (people, trees, cars, cities, airline reservations, etc.). Objects can perform actions which affect themselves and other objects in the world. Object-oriented programming (OOP) treats a program as a collection of objects that interact by means of actions.

2 OOP Terminology Objects, appropriately, are called objects.
Actions are called methods. Objects of the same kind have the same type and belong to the same class. Objects within a class have a common set of methods and the same kinds of data but each object can have it’s own data values.

3 OOP Design Principles OOP adheres to three primary design principles:
Encapsulation Polymorphism Inheritance

4 Introduction to Encapsulation
The data and methods associated with any particular class are encapsulated (“put together in a capsule”), but only part of the contents is made accessible. Encapsulation provides a means of using the class, but it omits the details of how the class works. Encapsulation often is called information hiding.

5 Example An automobile consists of several parts and pieces and is capable of doing many useful things. Awareness of the accelerator pedal, the brake pedal, and the steering wheel is important to the driver. Awareness of the fuel injectors, the automatic braking control system, and the power steering pump is not important to the driver.

6 Introduction to Inheritance
Classes can be organized using inheritance. A class at lower levels inherits all the characteristics of classes above it in the hierarchy. At each level, classifications become more specialized by adding other characteristics. Higher classes are more inclusive; lower classes are less inclusive.

7 Introduction to Inheritance

8 Variables Variables store data such as numbers and letters.
Think of them as places to store data. They are implemented as memory locations. The data stored by a variable is called its value. The value is stored in the memory location. Its value can be changed.

9 Naming and Declaring Variables
Choose names that are helpful such as count or speed, but not c or s. When you declare a variable, you provide its name and type. int heightInCentimeters,age; A variable's type determines what kinds of values it can hold (int, double, char, etc.). A variable must be declared before it is used.

10 Data Types A class type is used for a class of objects and has both data and methods. "Java is fun" is a value of class type String A primitive type is used for simple, nondecomposable values such as an individual number or individual character. int, double, and char are primitive types.

11 Primitive Types

12 Primitive Types Four integer types (byte, short, int, and long)
int is most common Two floating-point types (float and double) double is more common One character type (char) One boolean type (boolean)


Download ppt "Object-Oriented Programming"

Similar presentations


Ads by Google