
What is a class
A class is simply a specification of of how to construct something. WHAT??!! Well think of it as a blueprint that specifies how something is created and how it works. (google blueprint if you do not know what that is).
For example, car factories use blueprints to construct cars, architects use them to construct buildings. We, as computer scientists use them to construct our objects. Still not getting it? Consider chaging your major :P (just a joke)
Think of it as a simple container that has attributes (a water bottle has a size, a current storage, a type of drink. A student has an ID, a major, a certain age etc...).
Thus a class specifies how to construct a certain object and what attributes it will hold as well as what functionality does this class provide.
How do I code a Class?
Writing a Class is fairly easy:
public class Classname
{
// Attributes and functionality go here
}
public is the access modifier (leave this for later on).
class is a keyword that cannot be changed (until we learn about interfaces in CSC 245).
Classname is the ...hmmm..well....the name of the class.
Common Mistakes:
1- Filename is different from class name:
ex: example.java and public class Example
example.java should be the same as public class example
2- Filename of class name starts with a number:
ex: 123example.java or public class 123example
This is not possible - never start with a number.
3- Filename or classname has spaces in it:
ex: example 1.java or public class example 1