This discussion will begin with objects because classes are part of objects and it will make a little more sense learning the subject step by step. Examples of objects are all around us in all kinds of shapes and sizes. They also have different states of being, such as animate and inanimate. I have two monitors in front of me. One is a Dell 20 in. and the other is a Fujitsu 17 in. screens this list could go on and on with differences about each and every individual object that you may choose to describe. So as you can see I have two objects.
You know that I have two different items even though their names are similar, but are quite different. They were made by different companies but they are both monitors. Another example may be an automobile. It could be a Toyota, Altezza, 6 speed, red, hemi, headers, and type of wheels the list of attributes could be very long. IN the end it still comes back to the Altezza is still an automobile from in this case the automobile class. A program can also go a long ways just by adding to the instantiations of objects to fit the needs of your program. The different modes of the monitor object are either on or off.
Nowadays most monitors are color but another way to distinguish a monitor from the other is how many pixels and the width of the screen. A computer program is similar to this description because it also has two things in common with a monitor or any other object and that is the state and of the behavior of the object.
In object-oriented programming a class is basically a blueprint to give a clear meaning to an object. The class has several different parts such as fields, methods and constructors. A method is the part of a class that shows the states of the class such as standing, sitting, running, sleeping. The field portion of a class is used to show the name of the object such as automobile, teacher, bicycle, etc. As for the constructor it is used to create a new instance of a class. A constructor is used to expand a class in the program. For example in a program that holds data for an inventory, the constructor would be created to show all of the different fields with the pertinent information about the items that are in the list of items.
In more general terms a class is programming that is static and never changes once they have been created. Once it is created and the essential data is input into the program it will not change. However it can have instantiations and constructors to expand it. After an object is created it has a job to do and once it has accomplished its business then the garbage collector will come by and carry it off. The garbage collector has a way of determining when something has run its course and is no longer needed.
It makes sense that if a program is being used by more than one user no matter how often, the garbage collector will determine when it is no longer being used and rid the program of the unnecessary data. Also an object can have several changes while it is in existence. A program that is used like for example a bank ATM machine would be used over and over by different users with different names and account numbers and that would fit the description of a program object.
A class is a generalization of a concept and an object is a way of showing the differences and nuance of a class. Objects are created to show and use the different ways of describing a class in a program to fit the needs and uses by the user and programmers.
Tags: bicycle, blueprint, computer program, constructor, different companies, instantiations, list of attributes, object oriented programming, shapes and sizes, toyota altezza