Creating functions in classes
Question ID: 105789
0
0

What are the benefits of creating the functions inside classes?

Marked as spam
Posted by (Questions: 11, Answers: 5)
Asked on January 13, 2015 9:11 am
47 views
Answers (1)
0
Private answer

@Sarath_Medisetty

I'm not sure of you context for the question, but I'll give it a shot in case you or anyone else need a kick start.

In programing (at least in object oriented programming) you have ''classes''. You can think of a class as a grouping of similar items.

For example, if you had a class called ''Truck'', you might say that all ''Trucks'' have a color. All ''Trucks'' may have a make, a model, a model year, etc. These ''items'' are called properties.

An object is just a specific instance of a class. So, for our ''Truck'' class, we might have an object (or instance) of a truck that has the properties of a red 2006 Ford F150.

This is where the function inside of a class comes in. Just like a class can have properties, it can also have functions (or also called ''methods'' in some languages).

These functions provide the action. They can perform calculations, or in the case of our truck class we could have a function ''drive''. This would give us an action that we can do with our red 2006 Ford F150 (our object or ''instance'') of our class.

We classify items this way programmatically so that the code stays more portable (if a developer needs to add a property ''bed length'' to the truck class, its easier to find) and organized (just like putting your saved videos in one folder and pictures in another on your computer). There may not be much reason for a ''truck'' object (or class instance) to worry about a function called ''float'', but this might be a great function for a ''boat'' object instead.

I hope this helps...

Marked as spam
Posted by (Questions: 3, Answers: 168)
Answered on December 3, 2015 5:25 am
EyeOnTesting

Welcome back to "EyeOnTesting" brought to you by Orasi Software, Inc.

X
Scroll to Top