Could anyone please what the following is saying about instance and object:
If class is the general representation of an object, an instance is its concrete representation.
I know concrete means non-abstract. So what's actually general representation and concrete representation?
Car is a general representation having attributes (wheels, doors, colour, etc) and behaviour (start, stop, brake, accelerate, change gears, etc), also called a class.
Bob's Ford Focus (red, license plate LH 12 233) is an instance of class Car, also called an object.
My best advise would be to drop the dictionary.. looking up what concrete means and than trying to apply the definition to understanding what an author meant when he or she used concrete representation to describe an instance of an object is just wrong.
Look for other explanations of what objects, classes and instances of objects are, and I'm sure you'll find many with great examples.
Basically you could think of the class as a "recipe" or as a "template" (although I'm reluctant to say template for fear of causing confusion) and an instance as an "embodiment" of said recipe or template.. hence the concrete representation.
So you have the following, which is a class (the recipe):
class Human
{
private string Name;
private int Age;
public void SayHello()
{
// run some code to say hello
}
public Human(string name, int age)
{
Name = name;
Age = age;
}
}
And these are instances (objects)..
Human mike = new Human("Mike", 28);
Human jane = new Human("Jane", 20);
Human adam = new Human("Adam", 18);
They are embodiments, or concrete representations of our Human class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With