0% found this document useful (0 votes)
88 views23 pages

CSF213 L3

The document is a presentation on object-oriented programming concepts given at BITS Pilani, Hyderabad Campus. It defines key object-oriented concepts like classes, objects, encapsulation, inheritance and polymorphism. It provides examples of classes like Car and discusses how objects are instances of classes and have attributes and behaviors. It also explains concepts like abstraction, encapsulation, and the different forms of inheritance in object-oriented programming.

Uploaded by

Nilayan Ahmed
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
88 views23 pages

CSF213 L3

The document is a presentation on object-oriented programming concepts given at BITS Pilani, Hyderabad Campus. It defines key object-oriented concepts like classes, objects, encapsulation, inheritance and polymorphism. It provides examples of classes like Car and discusses how objects are instances of classes and have attributes and behaviors. It also explains concepts like abstraction, encapsulation, and the different forms of inheritance in object-oriented programming.

Uploaded by

Nilayan Ahmed
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 23

BITS Pilani

BITS Pilani
Hyderabad Campus

Dr.Aruna Malapati Asst Professor Department of CSIS

BITS Pilani
Hyderabad Campus

OBJECT ORIENTED PROGRAMMING CONCEPTS

Todays Agenda
Object Oriented paradigm Object Oriented concepts Basic terminology of Object Oriented principles

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Whats class?
Objects are grouped in classes. Class is a collection of objects having similar behavior and properties. A single object is simply an instance of class. Objects can not be instantiated (or created) without defining a class. Classes are defined whereas objects are created.

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Structure of a Class Definition


class name { declarations constructor definition(s) method definitions
attributes and symbolic constants how to create and initialize objects how to manipulate the state of objects
These parts of a class can actually be in any order
CS/IS F213 First Semester 2012-13 BITS Pilani, Hyderabad Campus

Example Class : car


class car
{ char name[20]; float price; char color[10];

void print_details();
}
CS/IS F213 First Semester 2012-13 BITS Pilani, Hyderabad Campus

Objects
class
Car

name color price void print_details( )

maruthi800 Attributes: name Maruthi 800 color red Price 2.5 lacs Methods: void print_details( )
wagonR Attributes: name WagonR color silky silver Price 4.5 lacs Methods: void print_details( )
CS/IS F213 First Semester 2012-13

objects

BITS Pilani, Hyderabad Campus

Whats Object?
Term Object Means Combination of Data (Attributes) and Logic (Behavior, Functions, Operations) of some real world entity. Every object has two parts :
Data Part [ Instance Fields in Java, Attributes or properties] Operations Part [ methods in java, Behavior] Examples : 1. Account Attributes : Account Holder, Account type [saving , current] ,Balance Operations : deposit, withdraw, 2. BOX: Attributes : length, width, height, color Operations : compute area, compute volume
CS/IS F213 First Semester 2012-13 BITS Pilani, Hyderabad Campus

Object State
Properties/Attribute Values at a particular moment represents the state of an object. Object may or may not change state in response to an outside stimuli.
States of Three Different INSTANCES of CAR CLASS

MARUTI800

MARUTIESTEEM

MARUTIZEN

Name : maruti800 Price : 200789 Color : Red

Name : marutiEsteem Price : 500789 Color : whilte

Name : marutiZen Price : 200789 Color : metallic white

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

A Simple Class, called car (partial)


class car { private char name[20]; char color[10]; int price; public car (char n[], char c[10],int p) { name = n; color = c; price = p; } public void print_details() { System.out.println(name +name); System.out.println(color +color); System.out.println(price +price); } }
CS/IS F213 First Semester 2012-13 BITS Pilani, Hyderabad Campus

constructor for car

A Simple Class, called car (partial)


class car

private char name[20];


char color[10]; int price;

constructor for car

public car (char n[], char c[10],int p) { name = n; color = c;


price = p; }

public void print_details()


{ System.out.println(name +name); System.out.println(color +color); System.out.println(price +price); }

car mar1 = new car(maruthi800, red, 200759); car mar2 = new car(maruthiesteem, white, 500789);
11
CS/IS F213 First Semester 2012-13 BITS Pilani, Hyderabad Campus

Abstraction in OOPs
Abstraction in Object Oriented Programming helps to hide the irrelevant details of an object. Abstraction is separating the functions and properties that logically can be separated to a separate entity which the main type depends on.
public class Car {
Engine engine = new Engine(); Wheel wheel = new Wheel(); int price; String name; String color;
public class Engine { int engineCapacity; int engineHorsePower; public class Wheel { String wheelName; int wheelPrice; void rotate(){ //Wheels method }

void internalCombustion(){ //Engine Method }

void move(){ //move forward }

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Abstraction has three advantages


By using abstraction, we can separate the things that can be grouped to another type. Frequently changing properties and methods can be grouped to a separate type so that the main type need not under go changes. This adds strength to the OOAD principle -"Code should be open for Extension but closed for Modification". Simplifies the representation of the domain models.

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Pillars of OOP
Encapsulation

Inheritance Polymorphism

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Encapsulation
Encapsulation means wrapping up of data and methods (operations , code) together Access to code and data is tightly controlled. Though, we can define what can be and what can not be accessible outside. [ public , private , protected ].
Methods Methods

Encapsulation keeps Data Part + Operation Part Together inside a capsule

Data
Methods Methods

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Encapsulation Example
class BOX

BOX Class

area()

{
private double length; private double width; private double height; public double area() { }
length width height

public double volume()


}

volume()

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Rules for Encapsulation

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Rules for Information Hiding

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Inheritance

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Inheritance

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Various Forms of Inheritance


Single Inheritance A

Hierarchical Inheritance
X X

BB

MultiLevel Inheritance A A

Multiple Inheritance B

B
C
CS/IS F213 First Semester 2012-13

NOT SUPPORTED BY JAVA

BITS Pilani, Hyderabad Campus

Examples

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

Summary
Class is a collection of objects. Objects cannot be instantiated. Abstraction is concealing the details of implementation from user. Encapsulation is creating a wrapper for the data or methods of your class. Inheritance allows us to inherit basic properties or methods of a class.

CS/IS F213 First Semester 2012-13

BITS Pilani, Hyderabad Campus

You might also like