- 2
What is instance?
2 Answers
+ 4
If you think of a Java class as a blueprint or plan to build a house. Then an instance would be the house that was built from that blueprint. You can make more than 1 house using the same blueprint. Each house (instance) can have its own different properties. One house might be blue and have tile floors in the bathroom, while another is brown with hardwood floors and luxury cabinets in the kitchen. Etc
class House {
...
}
House h1 = new House(...options...);
House h2 = new House(...options...);
House is the class
h1 and h2 are instances of the House class.
0
Instance is a kind of variable, which is declared in a class but outside of each and every block(methods, constructor etc).