Difference Between Class and Object
Class vs. Object
Object Oriented Programming, or OOP, is a very popular style of programming, due to its ability to handle more complex applications with a lot more code. This is because it organizes the data into objects that are comparable to real life objects. Class and object are two terms that are commonly used in OOP. In its most basic form, objects are the instantiation of classes.
In order to use objects in a program, you need to declare the properties and procedures in a class. For us to visualize this better, let’s discuss this using an example. If you want to create a program that deals with vehicles, you will need to create a class for vehicles. In the class you would create variables that will hold information relevant to vehicles. Values like passenger capacity, top speed and fuel capacity are typical along with procedures like start and stop. After creating the class for vehicles, you can now create objects in your application that are based on the vehicle class. You can create an object called car or motorcycle that is based on vehicles. You can then fill up the relevant information on the object, and use it as you deem fit in your application.
As you already may have deduced from the example discussed above, the information that you will really use in an application are stored in the object, and not in the class. The class only defines the structure of the data, and what each procedure or function does.
Another excellent feature of classes is the ability to inherit properties and procedures from another class. Classes that inherit the properties of other classes are called subclasses. This shortens the work needed to define another class. If you want to define a class specific to cars, you can simply inherit the properties and procedures in the vehicle’s class, as all cars are vehicles and will exhibit the same characteristics. The same is not done with objects, as there is really no practical use for globally inheriting an object’s data. The basic practice for programmers is to create a subclass, and create the object from the subclass.
Summary:
1. An object is an instance of a class.
2. You define all the properties and functions in a class, while you use them in an object.
3. Classes do not hold any information, while an object does.
4. You can create subclasses, but not sub-objects.
- Difference Between Sony Cybershot S Series and W Series - December 22, 2012
- Difference Between Samsung Galaxy S3 and iPhone 5 - December 21, 2012
- Difference Between Samsung Galaxy S2 (Galaxy S II) and Galaxy S 4G - December 20, 2012
Search DifferenceBetween.net :
Email This Post : If you like this article or our site. Please spread the word. Share it with your friends/family.
It’s good source of information