Explain class vs. instance with example using java.A class is a program construct which encapsulates data and operations on data. It is a blue print of an object.
An object can be called as an ‘instance’ of a class.
The variables and methods (without static key word) that are declared in the class, but not in the methods are called as instance variables which have one copy per object. Once an object is created, it is said that, an instance of the class is created.
Class variables and methods occur once per class where as the instance variables and methods occur once per instance of a class (per object).
|