class and object

S

Scott McPhillips [MVP]

asit said:
What is the difference between a class and an object ??

The same as the difference between a building blueprint and a building.
 
A

AnonMail2005

What is the difference between a class and an object ??
An object is an instance of a class. You can create
many objects of class Foo, for instance.

HTH
 
S

Szabolcs Ferenczi

What is the difference between a class and an object ??

Very good question. Many people are in error about it.

You have got some answers already.

I would try to give a more metaphysical answer: The class exists when
you write the program but the class does not exist when the program is
carried out. On the other hand, the object exists when the program is
performed and at that time there is no class in existence. Just try to
think about the origin of the words `class´ and `object´.

I mean that is the original idea.

A mistake is made when one tries to introduce the so-called class
variables. That violates the original concepts and makes some
confusion as well. Then the class is mixed up with the object. In C++
it is possible.

Best Regards,
Szabolcs
 
C

Chris Gordon-Smith

An object is an instance of a class. You can create
many objects of class Foo, for instance.

HTH

Well put - Thankyou.

A class is a type of thing that exists in a program. In a well designed
application, some of the 'high level' classes correspond to types of thing
that exist in that part of the real world that is relevant to the
application.

Chris Gordon-Smith
www.simsoup.info
 
R

Ravishankar S

What is the difference between a class and an object ??

Very good question. Many people are in error about it.

You have got some answers already.

I would try to give a more metaphysical answer: The class exists when
you write the program but the class does not exist when the program is
carried out. On the other hand, the object exists when the program is
performed and at that time there is no class in existence. Just try to
think about the origin of the words `class´ and `object´.

In languages supporting reflection, the class continues to exist in the
program as
an object.
 
A

Alf P. Steinbach

* asit:
What is the difference between a class and an object ??

That depends very much on the programming language.

The general language-independent notion is that a class is an object
type that defines the operations and data all objects of that class will
have. Thus objects of the same class are operationally similar in some
way defined by the class. And classes can be organized in a hierarchy.

In C++ an object is defined as a region of storage, and a C++ class is
just one specific mechanism to define a type. Thus a C++ object does
not have to be of class type. The C++ standard goes to pains to point
out where an object must be of class type, or where the rules are
different for objects of class type than for other objects.


Cheers, & hth.,

- Alf
 
T

Tim H

What is the difference between a class and an object ??

A class is a description of a thing. An object is a thing.


An orange is a fruit. It is round, juicy, sweet, and tart. It's skin
is about 1/8" thick and orange in color. It has seeds inside and the
meat comes in several sections.


I have just described to you an orange. That doesn't mean I have
given you an orange. Class vs Object.
 
S

Szabolcs Ferenczi

Ravishankar said:
In languages supporting reflection, the class continues to exist in the
program as
an object.

So then it is not a class but an object as you have already put it.

Best Regards,
Szabolcs
 
M

Michael

What is the difference between a class and an object ??

The above explanations are all very good. But how about one last one to
finish the cake with?

Tell me about dogs.

You'll probable come up with four legs, barks, has a tongue, can be
taught to play fetch... (Okay maybe not that exact list, but they are
very doggy attributes and behaviours).

Now how about a specific dog.

has four Long legs, barks Loudly, has a Rough tongue, has Been taught
to play fetch... (Okay doesn't have to be those descriptions, but that
describes one dog in terms of dogs in general (as above)).
 
D

dave_mikesell

In languages supporting reflection, the class continues to exist in the
program as
an object.

Isn't that just an instantiation of a class object (which itself has a
class definition)? Java.lang.Class is a class, and Class objects are
instantiated from it.

It doesn't make sense for a class to "exist" anywhere in a running
program, though you can create objects to represent it.

I'm getting dizzy.
 
K

Kai-Uwe Bux

Isn't that just an instantiation of a class object (which itself has a
class definition)? Java.lang.Class is a class, and Class objects are
instantiated from it.

It doesn't make sense for a class to "exist" anywhere in a running
program, though you can create objects to represent it.

I guess, that depends on what you mean by "exist". I could easily envision a
programming language where there is a keyword "type" that denotes a built
in type the values of which would be possible types. Basic operations on
types would include constructing objects, and hopefully some nice things
like obtaining information about available methods, overloaded operators,
the name of the type, etc. Thus, you could do

std::eek:stream & print_default_value ( std::eek:stream & ostr, type T ) {
T dummy;
return ostr << dummy;
}

...

print_default_value( int, std::cout );


or

print_default_value( some_class, std::cout );

Now, if some_class is a user-defined class, does it "exist" in the above
snippet at run-time or not?


Note that one could have functions like this:

type array_N ( type T, std::size_t N ) {
return ( T[N] );
}

which are somewhat like templates but not quite.


To me it seems that what we have in C++ is a way of defining type constants.
I don't see any reason why we could not have type valued variables, in
which case types would exist at run-time. In that case, types could be
objects (i.e., regions in memory) or they could be something else (like
functions or references).

I'm getting dizzy.

Why?


Best

Kai-Uwe Bux
 
T

Tim H

I guess, that depends on what you mean by "exist". I could easily envision a
programming language where there is a keyword "type" that denotes a built
in type the values of which would be possible types. Basic operations on
types would include constructing objects, and hopefully some nice things
like obtaining information about available methods, overloaded operators,
the name of the type, etc. Thus, you could do

I am sure such languages exist.

When I used to program FoxPro, everything was in the database. A
class definition was a just a row in a table (or something like that,
it's been years). You could do object introspection that way.

Tim
 
S

Szabolcs Ferenczi

Michael said:
On 2008-02-10 04:17:16 +1000, asit <[email protected]> said:
Tell me about dogs.

You'll probable come up with four legs, barks, has a tongue, can be
taught to play fetch... (Okay maybe not that exact list, but they are
very doggy attributes and behaviours).

Now how about a specific dog.

has four Long legs, barks Loudly, has a Rough tongue, has Been taught
to play fetch... (Okay doesn't have to be those descriptions, but that
describes one dog in terms of dogs in general (as above)).

Metaphysically speaking again, the class is a mere possibility whereas
an object is an actualization of it. E.g. when you write a method for
a class, you express that a _potential_ instance of that class _is
able to_ respond to a message that matches with the method signature.
The potential response to a message can be actualized only when you
make an instance. Otherwise there is no chance for it to happen.

So, your specific dog will be the actualization of the Dogness. It
will occupy a certain point in the space-time coordinates, which no
other dog instance can occupy. Two objects cannot be in the same place
at the same time. It will also have some specific, i.e. actualized,
characteristics that no other dog will have. Specific smell, patches,
etc. You have mentioned some too. Furthermore, it can actually
interact with some other objects. On the contrary, as being an
instance, it cannot interact with any classes as such.

For instance, your specific dog can chase a specific cat onto the top
of a tree but it cannot do the same with the cat class since they are
not on the same plain of existence.---Well, in some programming
notation: it can. In C++, for example, it is possible to implement it
that way, using so-called class variables. But then, you make use of
the low level nature of C++ as a programming notation and give up some
discipline as well.

Best Regards,
Szabolcs
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,183
Messages
2,570,965
Members
47,513
Latest member
JeremyLabo

Latest Threads

Top