• Post Reply Bookmark Topic Watch Topic
  • New Topic

Relationship between Class and Object  RSS feed

 
Luzie Blankenship
Greenhorn
Posts: 7
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Am I correct in saying that the relationship between Class and Object is the same as the relationship between a glass jar that you store things in? (Example: A glass jar(Class) that contains various berries(Objects))
 
salvin francis
Bartender
Posts: 1664
37
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, that does not sound right.

If you want to take an analogy, a class is like a cookie cutter and the objects are all the cookies made using that cookie cutter
 
Luzie Blankenship
Greenhorn
Posts: 7
C++ Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
glass jar that you store things in

I meant to say, "glass jar and the things you store in it".

I can't edit the original post for some reason.
 
salvin francis
Bartender
Posts: 1664
37
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Think of a class as a template. You can use this template to create several objects out of it.
 
Pete Letkeman
Ranch Foreman
Posts: 914
26
Android Chrome IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Luzie Blankenship wrote:I can't edit the original post for some reason.

Information on editing posts
https://coderanch.com/t/685738/edit-post

The short answer is when you get enough of a good reputation you can edit your posts.

By the way, welcome to CodeRanch.
 
Junilu Lacar
Sheriff
Posts: 11494
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Luzie Blankenship wrote:a glass jar and the things you store in it? (Example: A glass jar(Class) that contains various berries(Objects))

By your analogy, it would be the same as an egg carton (class) and eggs (objects).

I can kind of see why you might think that given the way some classes are written but the analogy is not apropos.

The cutter:cookies and template:object analogies are better fits.  Another is that of blueprint to product. A class is like engineering drawings and specifications for building a car. Objects, of course, are the actual cars you build out of the plans. Another example: A class is like a floor plan for an apartment unit. Objects are the actual apartment units that are built based on the plan.

 
Campbell Ritchie
Marshal
Posts: 56593
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Junilu Lacar wrote:. . . blueprint . . . for building a car. . . .
Which tells you things like where the engine goes, but omits information like colour of bodywork or chassis number. A class Car might have spaces in for colour or number, but wouldn't specify them directly.
Even less would the blueprints have such info as speed travelled, but that is an important feature of a car. But the class would have a space for speed.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!