LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-20-2005, 10:20 AM   #1
k1ll3r_x
Member
 
Registered: Sep 2004
Location: Laredo, TX
Distribution: Debian 11
Posts: 164

Rep: Reputation: 30
a Little Problem


I was reading the difference between class's and objects and i still dont get it, i read it again, and the same happened, i wonder if theres another site or if anyone could help me understand everything a littlebit better since i googled a bit and i found nothing
 
Old 01-20-2005, 10:28 AM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
An object is an instance of a class.


Or perhaps you could think of it as a class being a definition of an object, but not in fact an object by itself.
 
Old 01-20-2005, 10:32 AM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
it's exactly analogous to say.. a car. the car company designs it's brand new model on paper (well on some CAD pacakges now), and you then buy one, and it's yours. They created the class, which is not a real thing, just rules and plans and fabric color lists. you own the finished item, the object. but only one of them... and instance of the class.
 
Old 01-20-2005, 11:11 AM   #4
genderbender
Member
 
Registered: Jan 2005
Location: US
Distribution: Centos, Ubuntu, Solaris, Redhat
Posts: 396

Rep: Reputation: 31
When people do object orientated programming they seem to find this concept very difficult, dont worry if you dont fully understand it but I'll try and clarify a bit.

A class is a way of grouping objects together, so for example an operating system could be a class and an object would be fedora 3 or windows orwhatever. If you think of it as like a school class, thats one way of describing lots of different objects (in this case people) so the class is a class and john smith is an object from that class. To be honest the best way of explaining this is using confusing metaphores...

Let me know if you understand this any better
 
Old 01-20-2005, 03:22 PM   #5
leonscape
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Debian SID / KDE 3.5
Posts: 2,313

Rep: Reputation: 48
class A{}; NOT an object itself, just a definition of a class.
class B{};

A obj1; // An object of class A ( an instance )
A obj2;
B obj3;
B obj4

obj1, obj2, obj3 and obj4 are all objects.
obj1 and obj2 are class A.
obj3 and obj4 are class B.

I don't now how to say it more clearly.
 
Old 01-20-2005, 07:25 PM   #6
k1ll3r_x
Member
 
Registered: Sep 2004
Location: Laredo, TX
Distribution: Debian 11
Posts: 164

Original Poster
Rep: Reputation: 30
kewl i kind of got it now, its like my class would be the company, and the objects would be like the workers?
like saying a bunch of objects make a class
4 instance
System.out.print

as sayin folders.. like Folder System and then Folder Out and then folder Print
right??
 
Old 01-20-2005, 07:32 PM   #7
leonscape
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Debian SID / KDE 3.5
Posts: 2,313

Rep: Reputation: 48
No, I think you've not quite got it...

class Company{ int workers; }; // This is the class definition of Company with a member variable definition called workers

Company IBM; // IBM is an object of class Company
Company RedHat; // So is redhat

IBM->workers = 100; // workers here is a member of the object IBM
RedHat->workers = 10; // workers here is a member of the object RedHat

IBM->workers is not the same as RedHat->workers, The two objects are separate, though they are both defined by class, workers does not exist until an instance of the class is created.

Last edited by leonscape; 01-20-2005 at 07:34 PM.
 
Old 01-20-2005, 07:36 PM   #8
Hivemind
Member
 
Registered: Sep 2004
Posts: 273

Rep: Reputation: 30
A class is a type (could be complex, could be simple), just as "int" is a type. An object is an instance of a type or a variable of that type.
Code:
int a; /* a is an object of type int */
string b; /* b is an object of the class string */
But when talking about primitive types (i.e., int, char, bool etc) we generally refer to instances of those types as variables, not objects. Objects is usually used when the type is a class, but it essentially means the same things as variable.
 
Old 01-20-2005, 08:26 PM   #9
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
In most OO languages:
There's a top class whose name is Object, and all other classes derives from (extends) this one.
There's also a class named Class whose instances are both objects and classes ...
 
Old 01-20-2005, 08:34 PM   #10
leonscape
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Debian SID / KDE 3.5
Posts: 2,313

Rep: Reputation: 48
jillagre I think your saying that to confuse them Lets get the basic concepts across before we start mentioning the terrible terminology use by some languages.
 
Old 01-20-2005, 08:41 PM   #11
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
Don't confuse things like java.lang.Object or java.lang.Class with the idea of classes and objects. Those are both superclasses of every other class in java. Levels of abstraction that allow you some basic functionality in every class you create.
 
Old 01-20-2005, 09:38 PM   #12
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
I'm not confusing them, just pointing out the fact the vocabulary used can itself be quite confusing if you aren't prepared.

By the way, while java.lang.Object is indeed the superclass of all other java language classes, the same can't apply to java.lang.Class, which is a final Class whose every instance is matching every existing class, but not extended in any way by anything.

My remark wasn't limited to Java, but was for example applying to Smalltalk.

Metaclass (The class of a class) is also an interesting concept to explore ...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
perl problem? apache problem? cgi problem? WorldBuilder Linux - Software 1 09-17-2003 07:45 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration