0% found this document useful (0 votes)
51 views7 pages

Object-Oriented Programming (CS F213) : BITS Pilani

This document discusses abstraction and encapsulation in object-oriented programming and Java. It defines abstraction as managing complexity by suppressing details and focusing on essential features. Encapsulation is defined as binding data and methods together in a class, where access is controlled through public, private, and protected modifiers. Examples of abstraction include using sqrt() and strcmp() functions, and encapsulation is demonstrated with a BOX class that encapsulates length, width, height data with area() and volume() methods.

Uploaded by

SAURABH MITTAL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views7 pages

Object-Oriented Programming (CS F213) : BITS Pilani

This document discusses abstraction and encapsulation in object-oriented programming and Java. It defines abstraction as managing complexity by suppressing details and focusing on essential features. Encapsulation is defined as binding data and methods together in a class, where access is controlled through public, private, and protected modifiers. Examples of abstraction include using sqrt() and strcmp() functions, and encapsulation is demonstrated with a BOX class that encapsulates length, width, height data with area() and volume() methods.

Uploaded by

SAURABH MITTAL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Object-Oriented Programming (CS F213)

Module I: Object-Oriented and Java Basics


CS F213 RL1.2: Abstraction and Encapsulation

BITS Pilani Dr. Pankaj Vyas


Department of Computer Science, BITS-Pilani, Pilani Campus
CS F213 RL 1.2 : Topics

Abstraction
Encapsulation

2 Object-Oriented Programming (CS F213) Dr. Pankaj Vyas


Abstraction
https://en.wikipedia.org/wiki/Abstraction_(software_engineering)

Way of managing complexity by suppressing the complex


details
Abstraction refers to the act of representing essential features
that are of interest of the users without including background
details or explanation.
Users of a complex system are presented with a well defined
simple interface for its use
Classes use the concept of abstraction for hiding unnecessary
implementation/algorithmic details of its methods.
As user of any class what you should be aware about that
class ?

3 Object-Oriented Programming (CS F213) Dr. Pankaj Vyas


Abstraction: Simple Examples

Suppose you have to compute the square root of a


double type number in a C program. As a programmer
what You have to do.
o #include <math.h>
o Use sqrt() function
What you will do if you have to compare two strings in a
C program
o #include <string.h>
o Use strcmp() function

4 Object-Oriented Programming (CS F213) Dr. Pankaj Vyas


Encapsulation

Encapsulation means wrapping/binding up of


data-part (state) and methods (operations , code)
together in the form of a capsule.
Access to code (Methods) and data (instance
fields) is tightly controlled.
Through Encapsulation, developer of a class can
decide what and what can not be accessible
outside a class. [ public , private , protected ]
A class is a perfect example of an Encapsulation

5 Object-Oriented Programming (CS F213) Dr. Pankaj Vyas


Encapsulation : Examples

Encapsulation keeps Data Part + Methods Methods

Operation Part of an object Data


together inside a capsule Methods Methods

class BOX
{
private double length;
private double width;
private double height; Class Capsule

public double area() { }


public double volume() { }
} // End of class BOX

6 Object-Oriented Programming (CS F213) Dr. Pankaj Vyas


Thank You

7 Object-Oriented Programming (CS F213) Dr. Pankaj Vyas

You might also like