Y
Y
yakushechkin2014-07-21 11:00:47
Java
yakushechkin, 2014-07-21 11:00:47

What is the difference between class, object and instance?

I'm learning the Java language and now I'm faced with the problem that I don't quite understand the difference between these terms.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
GavriKos, 2014-07-21
@yakushechkin

There is a chair - this is a class. It has some parameters such as the number of legs and the area of ​​the landing surface. It's just that these parameters are there, and that's all, without values. You can also call them properties. The particular chair you are sitting in is an instance of the class. It already has specific property values, which makes it different from other chairs. Something like this.

M
Maxim Vasiliev, 2014-07-21
@qmax

@vdem has a bad, bad example!
Vasya and Masha have a common method - to fuck.
However, the implementation (and maybe even the signature) of this method is completely different for them.
Here is the presence of a basic abstract class Person with a virtual method to fuck.
And two inherited classes M and F, generally speaking, with very different interfaces.

V
vdem, 2014-07-21
@vdem

Let's say there is a class Person. It has methods (jump, run, eat, sleep), properties (height, weight, - uninitialized). There are Vasya and Masha, instances of the Person class. Accordingly, they have all the methods that are declared in the Person class, their properties are already initialized when an instance is created.

Человек вася = новый Человек(200, 50);
Человек маша = новый Человек(150, 120);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question