• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Explain instance in java

 
Rajendra Prakash
Ranch Hand
Posts: 293
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends, can you explain instance in java. In general instance means "occurence of something" . In java what is instance.
 
Ankit Garg
Sheriff
Posts: 9529
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please take time to Carefully Choose One Forum when you start a topic. The servlet forum is for servlet questions. I'll move it to the appropriate forum...
 
fred rosenberger
lowercase baba
Bartender
Posts: 12203
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in java, an instance is an occurrence of the object.

Someone writes a java file to define a class. This is like a blueprint on what the object looks like and what it does.

Just like you can use the same blueprint over and over to build the same house many times, you can do the same thing with a class. you can make many instances, each of which live in their own place independently of each other.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50284
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch

Useful answer, but it would have been easier to read with the CODE button. As you are new, I have edited your post.
 
s.palanivel rajan
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
instance is nothing but the object of the class...
we can create any no of instance per class..
for example...
a blue print of the cycle will be a class and a single cycle will be the instance...
 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you think of a class as a data structure or a type definition. You can think of instance as a snap shot that shows you what values each of the constituent elements of that data structure have at a particular time.

If class is an abstraction. An object is concrete implementation.
For e.g: Chair is an abstraction(an idea).It is intangible. A revolving chair is an implementation of the idea. It is tangible.

 
Campbell Ritchie
Sheriff
Pie
Posts: 50284
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Better to say "chair" is abstract, and "a red chair" is concrete. "Revolving chair" would be a subtype of "chair".
 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Better to say "chair" is abstract, and "a red chair" is concrete. "Revolving chair" would be a subtype of "chair".


My mistake.

Yes, color would be an attribute;"Red" is the color that the chair instance has. "Revolution" is a functionality so subtyping would be a better fit to describe it.

Thanks CR!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic