In simple language when it says : Instances of types are called objects
it means, when you have defined a prototype or a blueprint and you want to use that blueprint you need to declare an object of that type.
You have different types.
- Primitive data type like int, long, char, short etc
- User defined data types like Class, Structure etc
- Derived data types like Function Array Pointers etc
And to use any data type you need to have an object for that type.
For example : Primitive data type , you have int i;
When you declare this way, you mean you need a variable/object of 4 bytes of memory.
So here i
is your object. So you cannot use the object i
without the type.
Similarly you may require different objects for different types.
For non-primitive types also the same logic apply.
Suppose you have a class as below :
class Student {
public:
int rollNum;
String name;
}
This is your blueprint, your type. When you need to use class variables you need to create an object for your type. like below :
Student s;
And you will be able to access the variables and assign them values according to your wish.
s.rollNum = 10;
s.name = "Martin";
So your object is : s
which is a type of Student
More from a blog post on "Class vs Object vs Instance":
In short, An object is a software bundle of related state and
behavior. A class is a blueprint or prototype from which objects are
created. An instance is a single and unique unit of a class.
Object Real world objects shares 2 main characteristics, state and behavior. Human have state (name, age) and behavior (running,
sleeping). Car have state (current speed, current gear) and state
(applying brake, changing gear). Software objects are conceptually
similar to real-world objects: they too consist of state and related
behavior. An object stores its state in fields and exposes its
behavior through methods.
Class Class is a “template” / “blueprint” that is used to create objects. Basically, a class will consists of field, static field,
method, static method and constructor. Field is used to hold the state
of the class (eg: name of Student object). Method is used to represent
the behavior of the class (eg: how a Student object going to
stand-up). Constructor is used to create a new Instance of the Class.
Instance An instance is a unique copy of a Class that representing an Object. When a new instance of a class is created, the Compiler or
JVM (for java) will allocate a room of memory for that class instance.