Can any one tell me the real example for Class and Object. but please dont give example like this.. ( class as a vehicle. An object as a lorry or car or rocket. A lorry is an object, so is a car and a rocket too. But all of them are vehicles.) Its seems the example for inheritance. I think its like parent/child relationship. Like super class is Animal. Say subclass Elephant, Bear and Tiger are example for objects. subclass Tiger has its two types of behavior, 1) Own behavior - like (kills others animals and eats) 2) Common behavior - like (All animals don't have 6th sense and lives in forest and so on.. )
please any one give me the proper definition for Class & object with examples.
Disagree about all. And it is class, not "Class", object not "Object."
What colour is a car? What speed is it travelling at? "Car" is a class. Cars can have colours, numberplates, can travel at different speeds. Aminals may be eating at the moment, or sleeping at the moment. Is a lion eating or sleeping just now?
"Car" is a subclass of "Vehicle" and "Lion" is a subclass of "Animal". A class records that an animal might eat or sleep, that a car might travel at 20mph or 100mph, but it doesn't record that "Lion" is eating or hunting, nor that "Lion" is asleep or awake. It doesn't record a speed or colour for "Car," either.
You can create an object from the Car class and record that it is coloured black, that it is travelling at 50mph. You can create three objects from the Lion class and record that one is eating, one asleep and the third is hunting.
A class is an abstract definition, an object is a concrete implementation.
In a class file, you define the parts of the thing.
"my class will store THESE pieces of information, and let you do THESE things with it".
an object is a SPECIFIC INSTANCE of said class. myObject stores 'blue', '100', 'stick', and 'orange'.
put another way, the class file is the blueprint. an object is a house. you can use the same blueprint to build hundreds or thousands of houses that all behave the same (lock front door, turn on living room chandelier, fill bathtub), but have different color bedrooms, some have siding and some are brick, etc.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
"Car" is a subclass of "Vehicle" and "Lion" is a subclass of "Animal".
That really depends on the kind of system you build. It's not too hard to imagine a system where Lion would in fact be an instance of the Animal class, for example a reference work on animals.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Joined: Jul 11, 2001
Here is my understanding of those terms:
An object is an entity that has both state and behavior.
A class is a template for objects. It is a common definition of both the behavior and the possible states the objects posses that are created using that template (the instances of the class).