Difference Between Similar Terms and Objects

Difference Between Class and Object

software-keyboardClass 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.


Search DifferenceBetween.net :

Custom Search



1 Star2 Stars3 Stars4 Stars5 Stars (5 votes, average: 3.80 out of 5)
Loading ... Loading ...


Email This Post Email This Post : If you like this article or our site. Please spread the word. Share it with your friends/family.



See more about : , ,

Leave a Response

Please note: comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

Articles on DifferenceBetween.net are general information, and are not intended to substitute for professional advice. The information is "AS IS", "WITH ALL FAULTS". User assumes all risk of use, damage, or injury. You agree that we have no liability for any damages.


Protected by Copyscape Plagiarism Finder