---
title: "Is a function an example of encapsulation?"  
description: "Is a function an example of encapsulation?"  
author: "Anonymous User"  
published: 2013-06-12  
updated: 2013-06-12  
canonical: https://www.mindstick.com/forum/1051/is-a-function-an-example-of-encapsulation  
category: "oops"  
tags: ["oops"]  
reading_time: 1 minute  

---

# Is a function an example of encapsulation?

By putting [functionality](https://www.mindstick.com/blog/136/using-watermark-functionality-in-textbox-by-jquery) into a [function](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server), does that alone constitute an example of [encapsulation](https://www.mindstick.com/articles/12229/encapsulation-and-access-specifier) or do you need to use [objects](https://www.mindstick.com/forum/145447/what-are-objects) to have encapsulation?

I'm [trying](https://answers.mindstick.com/qa/93698/6-mistakes-couples-are-trying-to-save-money) to understand the [concept](https://www.mindstick.com/blog/79/routing-concept-in-dot-net) of encapsulation. What I thought was if I go from something like this:

n = n + 1

which is executed out in the wild as part of a big body of code and then I take that, and put it in a function such as this one, then I have encapsulated that addition [logic](https://www.mindstick.com/articles/331924/best-ways-to-improve-your-logic-building-skills-for-programming) in a [method](https://www.mindstick.com/forum/166/webservice-method):

```
addOne(n)    n = n + 1    return n
```

\
Or is it more the case that it is only encapsulation if I am hiding the details of addOne from the outside world - like if it is an object method and I use an [access](https://www.mindstick.com/articles/12994/how-foreigners-can-access-blocked-websites-in-china) modifier of [private](https://www.mindstick.com/blog/11097/java-access-modifiers-the-public-and-the-private-modifiers)/protected?

## Replies

### Reply by Vijay Shukla

Hello Ankita Pandey!\

Encapsulation is a process in which attributes(data member) and behavior(member function) of a objects in combined together as a single entity refer as class.\


---

Original Source: https://www.mindstick.com/forum/1051/is-a-function-an-example-of-encapsulation

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
