What are “Classes” in programming and how are they distinct from functions? What about their applications?

275 views

What are “Classes” in programming and how are they distinct from functions? What about their applications?

In: 10

21 Answers

Anonymous 0 Comments

Imagine a class like a blueprint of some object: like a house. Your code defines a “house” blueprint that has some attatched properties and functions, and then you can use that blueprint to create as many houses as you want. Because you know what the blueprint contains you can know what functions and properties every house has even if each induvidual house may have different values. Every house could have a “color” value that tells you what the color of it is, or a “rooms” value to store all the rooms of the house, and a “open()” and “lock()” function to affect if the front door is locked or not, and you can rely on the houses having those things because they were created from a house blueprint that say they have these things.

A function is just a block of code that you’ve given a name: you call it and it does something. A Class can have multiple functions attatched to it, but it also stores data. The idea being that if you have a Class you can create an instance of that class, and that instance is a convinient little package that has all the relevant code directly built in, or can be the foundation for a derived class.

You are viewing 1 out of 21 answers, click here to view all answers.