0
What is exactly an instance in Java?
I'm approaching to Java, because I've some projects to do with it, but I didn't understand this thing. Can you explain me what it is like I'm 5?;-)
4 Answers
+ 3
An instance is an istantiated object of a class.
For Example, i have the "Animal" class, with "Name, Animal_Type, Age".
Then, in the code, I write something like:
Animal one = new Animal(Tom, Cat, 25)
Animal two = new Animal(Jerry, Mouse, 25)
Animal three = new Animal(Mc.Scrooge, Duck, 69)
"Animal" Is the class.
One, two and three, are instances of the class "Animal"
+ 2
it's a bit more abstract.
You have a class "Animal", but no object yet.
Then, when you CREATE an object of that class, you are instantiating it.
So, with the code:
Animal one = new Animal(Tom, cat, 25)
You are INSTANTIATING (Creating an object of a certain class) and ASSIGNING it to the variable one.
Maybe here they explain the concept in a better way. My english is not the best. :D
https://stackoverflow.com/questions/1215881/the-difference-between-classes-objects-and-instances
+ 1
you explained that very well thanks
0
is {animal one = new Animal(Tom,Cat,25)} the
entire instance?
or just {new Animal(Tom,Cat,25)?
thanka