I was wondering what is difference between instance and object?
ans.
An instance, in object-oriented programming (OOP), is a specific realization of any object. An object may be varied in a number of ways. Each realized variation of that object is an instance. The creation of a realized instance is called instantiation.
Each time a program runs, it is an instance of that program. In languages that create objects from classes, an object is an instantiation of a class. That is, it is a member of a given class that has specified values rather than variables. In a non-programming context, you could think of "dog" as a class and your particular dog as an instance of that class.
ans.
An instance, in object-oriented programming (OOP), is a specific realization of any object. An object may be varied in a number of ways. Each realized variation of that object is an instance. The creation of a realized instance is called instantiation.
Each time a program runs, it is an instance of that program. In languages that create objects from classes, an object is an instantiation of a class. That is, it is a member of a given class that has specified values rather than variables. In a non-programming context, you could think of "dog" as a class and your particular dog as an instance of that class.
It is very simple but very important
Take a general example: what is the general meaning of object? its nothing but which occupies some space right....keep that in mind we now talk about Object in java or C++
example: here I am creating Object Student std=new Student();
where Student is a Class and std is a Object because we Created a memory for std with the help of new keyWord it means it internally occupies some space in memory right thats y we call std as Object
if you won`t create memory for an object so we call that object as instance.
example: Student std;
here Student is a class and std is a instance(means a just a copy that class),with this we won`t do anything untill unless we create a memory for that.
Thats all about object and Instance :)
Take a general example: what is the general meaning of object? its nothing but which occupies some space right....keep that in mind we now talk about Object in java or C++
example: here I am creating Object Student std=new Student();
where Student is a Class and std is a Object because we Created a memory for std with the help of new keyWord it means it internally occupies some space in memory right thats y we call std as Object
if you won`t create memory for an object so we call that object as instance.
example: Student std;
here Student is a class and std is a instance(means a just a copy that class),with this we won`t do anything untill unless we create a memory for that.
Thats all about object and Instance :)
No comments:
Post a Comment