Question:
In programming, what exactly are classes?
Hello!
2011-12-16 13:17:37 UTC
It doesn't make any sense to me, what's a class?
Like can you give me a practical item or technical device that can be compared with a class in programming? What function does a class have?
Seven answers:
Gardner
2011-12-16 13:26:32 UTC
http://en.wikipedia.org/wiki/Class_%28computer_programming%29



A good way to think of a class would be for instance a form that you fill out. The blank form (say a job application) would be the class. When you make a copy of it, that is creating a new instance of that empty class. When you fill out the form you are assigning values to the individual properties of the form.



Classes can also contain other classes. So an employee class could for example contain that employees application class and the data that was assigned to it.
Ruding E
2011-12-17 03:39:53 UTC
Class is basically a set of codes about an object



Once you become a programmer, you will be writing a lot of codes for applications. The more applications you build the more and more codes you will write.



Perhaps the best way to get you to understand what classes or a class is, is to find out why does a class exists?



As you write more codes after codes, you will begin to notice that some of the codes you are writing are actually the same codes you have written in the past.



Wouldn't it be nice to not rewrite the same code over and over? It is possible to not rewrite the same codes over and over by writing (coding) it once and package it up into "something special".

So when you need to reuse that code again, you don't have to rewrite it again. All you have to do is to call-a-copy-of-it from that "something special". To call-a-copy-of-it ( "it" refers to the 'something special' ) in programming lingo is to instantiate.



That "something special" in programming terminology is called a class. A class is an already-made-code(s) that can be re-used in your application simply by calling its name.Once a copy is made from the original class it is considered an instance of that class-meaning it inherits (copied) everything (functions, methods, properties, events) in the class.



The functions that a class can have varies, or depend on what class you build. Because classes can represent anything (objects) in the real world-physical or abstract- they may have different function, methods, properties and events in them.



But first let me try to make it easier for you to understand what is a function at its basic.

Function falls along class for the fact that they are also packaged codes. Reusable (By calling its name) codes so you don't have to spend more time coding or writing the same code.



A comparable great example of class is a blueprint of a house.



This blueprint can be re-use to build many houses that look exactly the same. In other words:

This class (blueprint) can be instantiated (followed or copy) to make instances (copies of blueprint in it physicality) of this class.

-----------------------------------------------------

Lets build a simple house using pseudo codes:

-----------------------------------------------------

1.Build a foundation

2.Build the north wall

3.Build the east wall

4.Build the south wall

5.Build the west wall

6.Build the roof



->Now we just code an object by writing codes.

You can build the same exact house as many times as you want by coding or rewriting the same codes 1-6 over and over. But why do all that tedious and repetitive coding when you can package all those up into a class and simply call or instantiate the class. Ok, lets turn or package up those codes into a class.



Class BuildASimpleHouse

1.Build a foundation

2.Build the north wall

3.Build the east wall

4.Build the south wall

5.Build the west wall

6.Build the roof

End Class





Now if you want to build the same house again and again?

Instead of coding the same codes over and over, all you have to do is call that class or instantiate it.

Lets build 6 houses without rewriting the 1-6 set of codes 6 times:



Examples in pseudo codes:



House1 as New BuildASimpleHouse

House2 as New BuildASimpleHouse

House3 as New BuildASimpleHouse

House4 as New BuildASimpleHouse

House5 as New BuildASimpleHouse

House6 as New BuildASimpleHouse



Class is basically a set of codes about an object.
chaqui
2011-12-16 22:36:30 UTC
A class is a definition of an object. And an object is an entity that is specializes in something and is able to manipulate its own data. For example a car or a TV set are objects. You send them requests (go faster, change channel) and they know how to manipulate their own data and structure to fulfill that request.

To define those objects in a computer language you use a construct called "Class". In that construct you define the internal components of the object (variables) and the behavior they can perform (methods).
Locoluis
2011-12-16 21:28:49 UTC
A class is an abstract concept, a set of attributes and methods that define a class of objects. For example, "car" is a class.



A class is not alone in the universe, you can establish inheritance relationships between classes. For example, "car" is a subclass of "motorized vehicle". Other subclasses of "motorized vehicle" include "truck", "motorbike", "bus", etc. Subclasses of "car" could be "sedan", "coupé", "antique car", "sports car", etc.



An object is an instance of a class. All objects of a certain class share the same set of attributes and methods. For example, I have 20 cars. Each car is an object of class "car".



An attribute is an item of data about the object. Attributes of cars would be: fuel tank capacity, maximum speed, 0-60 mph acceleration time, color, number of seats, number of doors, brand, etc.



A method is something that can be done with objects of certain class. For example, cars can be started, accelerated, turned left or right, brake, constructed, destroyed, etc.
jplatt39
2011-12-16 22:00:45 UTC
Think of it this way: it is a special kind of record which restricts what you can do to the information stored on it to the methods (procedures and functions) which you define to act on them.
2011-12-16 21:25:18 UTC
Since your a bit of a "newbie" ill tell in the simplest way possible.

A class is a blank page where you put your code in simple as
2011-12-16 21:19:03 UTC
http://en.wikipedia.org/wiki/Main_function


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...