Let's say you want to store the following:
- Individual employee information for a company
- Items for sale at an e-commerce site
- Date on the toys belonging to your children
You would use a class for this.
A class groups together variables or constants used to represent an object. Variables or constants associated with a class are called properties.
A class can also contain functions that perform specific tasks. Functions associated with a class are called methods.
Once you have a class, you can create instances of that class. Imagine you are creating an app for a zoo. If you have an Animal class, you can use instances of that class to represent animals at the zoo. Each of these instances will have different property values.
Here's what a class declaration looks like:
class className {
property1
property2
property3
method1() {
code...