ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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
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.
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...
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??
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.
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.
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
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 ...
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.
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.
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789
Rep:
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 ...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.