9

A class is a binding of methods and variables in a single unit.
An object is an instance of a class.

These are definitions for classes and objects in programming books. My friend said that a class is a blueprint of an object. An object is a real "thing" of a blueprint. He has given an example: if Company is a class, INFOSYS, CTS, and TCS etc are objects. Whenever I think about classes and objects, these definitions confuse me. If channel is a class, what would be objects for the class? If water is a class, what would be objects of class? Can you clarify?

6
  • 2
    You should read a good book and work through some examples...
    – home
    Dec 8, 2012 at 6:47
  • Your friend is wrong. Classes themselves can be considered objects. Dec 8, 2012 at 6:49
  • 1
    But only in certain languages... best get the groundwork down first before tackling that
    – Sheena
    Dec 8, 2012 at 7:10
  • A class is a Job ad, an object is the person that actually fills the position.
    – Textmode
    Sep 21, 2013 at 5:54
  • See the answer to this question What is the difference between Type and Class?
    – mins
    Mar 16, 2015 at 7:21

11 Answers 11

17

If channel is a class, Start Sports, BBC, and ESPN are its objects. If water is a Class, "Fresh Lime Water" and "Soup" are its objects.

Although you might find this explanation vague, this is the answer that I could think of.

Here is how you can learn about and distinguish classes:

Say you have a class "CAR"

Its objects are Hyundai, Ford, Suzuki. It will have the same methods but different designs -> this is how you can relate objects and classes with the real world.

2
  • thank you for your clarification.If Channel is a object what would be a class? Dec 8, 2012 at 7:11
  • I already mentioned it in my Answer Please Read it. If CHannel is the object ESPN, START sPORTS, TEN SPORTS, BBC, CNBC etc. are its objects
    – droidchef
    Dec 8, 2012 at 7:13
5

A class specifies the behavior of its instances.

A class is an instance of a class too (class for a class is named a "metaclass").

A class is an abstraction. You find a class by finding generic properties applying to a group of objects.

Then a class is a template which defines the methods (behavior) and variables (state) to be included in a particular kind of object

Recognition of classes (outside classroom) requires experience.

Read anything from Alan Kay, he is the inventor of Object Technology, and one of the inventors of Smalltalk, the only pure objects environment as of today.

3

I'll give you a classic explanation, you can find different versions of this all over the place.

A class is like a blueprint. Say you want to build a car, the first thing you would need is a plan, This is the class. The plan will describe 'methods' such as brake and hoot. It will also describe the various components of the car. These are variables.

A car object is an instantiation of a car class. You can have lots of these for one car class.

For example:

class Car:
    def __init__(self,color):
        self.color = color

    def hoot(self):
        "do stuff"


red_car = Car('red')
red_car.hoot()
blue_car = Car('blue')
blue_car.hoot()

Now, depending on the language you are using classes themselves can be objects (this is the case in Python). Think of it this way: All blueprints have some stuff in common. That common stuff is described in the blueprint's class (which is in itself a blueprint).

Then on the point of 'water' as a class you can approach it in a few ways depending on what you want to do:

way 1:

rather have a class called Liquid with variables describing stuff like viscosity, smell, density, volume, etc. Water would be an instance of this. So would orange juice

way 2:

say you were putting together a game with a bunch of blocks that would be made up of different terrain. You could then have classes such as Grass, Water, Rock, etc (think Minecraft). Then you can have a water class instance (a water object) occupy a specific position on the map.

3

I do not have much programming experience, but a friend of mine made a good example of defining a class and a object. I'll try my best to use human language as possible.

Take an horse. What makes you know that this animal is an horse and not a... dog? Because it has four legs, it's a big animal, it's very strong and it can run. Well, you just defined a 'horse' class in your head! Now, you are going to see a white female horse called 'Pollyanna' and a black male horse called 'Demon'. As soon you see them you know that they are horses, so they belong to the 'horse' class. What makes them different? The sex and the color... Those are properties of the 'horse' class. 'Pollyanna' and 'Demon' are two objects, they are the real thing, things you can actually touch and ride. Their properties, sex and color are also different. Pollyanna is white and female. Demon is black and male. Those defined properties are what distinguishes one object from the other. One horse from the other. But they still belong to the same class: they are always horses!

More technical now... A class is a more abstract definition of something. A blueprint. An object is the real thing that belongs to that class. When you create a new object from a class you are instantiating an object (aka creating an instance).

Hope this helps, and if it doesn't sorry... As I said before, I do not have much programming experience :)

Gianluca

0

In the real world, you'll often find many individual objects all of the same kind. There may be thousands of other channels in existence, all of the same make and model. Each channel was built from the same set of blueprints and therefore contains the same components. In object-oriented terms, we say that your channel is an instance of the class of objects known as channel. A class is the blueprint from which individual objects are created.

class Channel {

    ChannelType type = 0;
    int employeeCount = 0;


    void setType(ChannelType newType) {
         type = newValue;
    }

    void addEmployer(int increment) {
         employeeCount= employeeCount+ increment;   
    }

    void removeEmployer(int decrement) {
         employeeCount= employeeCount- decrement;
    }

    void printStates() {
         System.out.println("type :" +
             type + " employee count:" + employeeCount);
    }
}

The design of this class is based on the previous discussion of Channel objects. The fields typr , employeeCount represent the object's state, and the methods (setType, addEmployer, removeEmployer etc.) define its interaction with the outside world.

You may have noticed that the Channel class does not contain a main method. That's because it's not a complete application; it's just the blueprint for Channels that might be used in an application. The responsibility of creating and using new Chennel objects belongs to some other class in your application.

class Channel Demo {

    public static void main(String[] args) {

        // Create two different 
        // Channel objects
        Channel BBC= new Channel ();
        Channel NTV = new Channel ();

        // Invoke methods on 
        // those objects
         BBC.setType(channeltype.NEWS);
         BBC.addEmployer(500);
         BBC.printStates();

         BBC.setType(channeltype.SPORT);
         BBC.addEmployer(300);
         BBC.printStates();


    }
}

The output of this test prints for the two channels:

type :NEWS employee count: 500

type :SPORT employee count: 300

0

in grammar Common Noun is Class and Proper Noun is Object.

0

An object has a limited lifespan,object are created and eventually destroyed. Also during that lifetime,the object may undergo significant change

0

Class

  1. A way to bind data and associated functions together.
  2. Class have many objects.
  3. Class is a template for creating objects.
  4. It is logical existence.
  5. Memory space is not allocated, when it is created.
  6. Definition (Declaration) is created once.
  7. Class is declared using "class" keyword.

Object

  1. Basic runtime entity in object oriented environment.
  2. Object belongs to only class.
  3. Object are a implementation of class.
  4. It is physical existence.
  5. Memory space is allocated when it is created.
  6. It is created many times as you required.
  7. Object is the instance or variable of class.
0

Now object can be anything like bus,car,mobile or man etc.

For example take samsung smartphone. Now samsung smartphone is an object we know that. To create that samsung smartphone we need a blueprint(Class). Now there are going to be thousands samsung smartphones now they can be of different color like blue or black and also they can have different ram or storage. Now samsung smartphone with blue color, 4gb ram , 256gb storage this is one instance of that object.

So,

  • class - blueprint of samsung smartphone
  • object - samsung smartphone
  • instance - samsung smartphone with specific features

Class is blueprint of object and instance can be consider as single occurrence of object.

1
-1

An object is an identifiable entity with some characteristics and behavior. It represents an entity that can store data and its associated function.

A class is a group of objects that share common properties and relationship. It represents a group of similar objects.

-1

The term class and object are definetly related to ine another, but each term hold its own distinct meaning. Let's start out by explaining what the term class means. Class refers to the actuall writtten piece of code which is used to define the behaviour of any given class.so a class us a static pice of code that consists if atributes which do not change during the execution of a orogram.While Object refers to an actual instance instance of a class.Every ibhect must belong to a class

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.