You are on page 1of 13

Object-Oriented Programming

Lecture-1 [OOP Basics] OOP Concepts  What  What  What  What is is is is an object? a Class? Inheritance? an Interface? 2 Object Oriented Programming .

OOP Concepts 3 Object Oriented Programming .

What is an object?  Look around you and identify some objects  Real world objects share two characteristics   They all have state They all have behavior  Identifying the state and behavior for real-world objects is a great way to begin thinking in terms of object-oriented programming  Two Questions    What possible states can this object be in? What possible behavior can this object perform? Write down your observation  Real world objects vary in complexity (Radio. Table Lamp)  Objects may contain other objects  These real world observations all translate into object oriented programming 4 Object Oriented Programming .

a fundamental principle of OOP 5 Object Oriented Programming .)     Software objects are conceptually similar to real world objects: they too consist of state and related behavior An object store its state in fields and exposes its behavior through methods Methods operate on objects internal state and serve as the primary mechanism for object-to-object communication Hiding internal state and requiring all interaction through an object’s method is known as data encapsulation .What is an object? (Contd.

a method to change gears could reject any value that is less than 1 or greater than 6. if the bicycle only has 6 gears. Benefits of building code into individual software objects  Modularity  Information-hiding  Code re-use  Plug-ability and debugging ease 6 Object Oriented Programming .By attributing state and providing methods for changing that state.)   Bicycle .What is an object? (Contd. the object remains in control of how the outside world is allowed to use it. For example.

What is a Class?      A class is a blueprint or prototype from which objects are created A class defines the general nature of a collection of objects of the same type The process creating an object from a class is called instantiation Every object is an instance of a particular class. There can be many instances of objects from the same class possible with different values for data 7 Object Oriented Programming .

Example objects Object References redRose class Rose blueRose class Object Oriented Programming 8 .

current gear)  Yet each also defines additional features that make them different: tandem bicycles have two seats and two sets of handlebars. and tandem Bikes all share the characteristics of bicycles (current speed. current pedal cadence. road bikes.What is Inheritance?  Different kinds of objects have a certain amount in common with each other  For example mountain bikes. road bikes have drop handlebars etc  Object-oriented programming allows classes to inherit commonly used state and behaviour from other classes 9 Object Oriented Programming .

What is Inheritance? 10 Object Oriented Programming .

What is a Interface? • Objects define their interaction with the outside world through the methods that they expose • Methods form the object's interface with the outside world • The buttons on the front of your television set. are the interface between you and the electrical wiring on the other side of its plastic casing. for example. You press the "power" button to turn the television on and off 11 Object Oriented Programming .

Questions  Real-world objects containstate behaviour _____ and ________  A software object's state is stored in itsfields _____  A software object's behaviour is exposed through _______ methods  Hiding internal data from the outside world. and accessing it only through publicly exposed methods is known as data ___________ encapsulation  A blueprint for a software object is called aclass ____  Common behaviour can be defined in a sub-class _________ and inherited into a _______ super-class 12 Object Oriented Programming .

Copyright © Oracle Sun Microsystems 13 Object Oriented Programming .THANK YOU 1. The material presented in these slides is used only for academic purpose 2.