类和对象之间的区别[重复]

时间:2021-11-04 13:20:44

This question already has an answer here:

这个问题在这里已有答案:

I have a question about difference between Class and Object:

我对类和对象之间的区别有疑问:

we have :

我们有 :

  • Book
  • Special-Book
  • Matematics special-book
  • informatic special-book
  • programming science book (ISBN 12345)
  • 编程科学书(ISBN 12345)

my question is as follows: whats betwen this elements class and what is object?

我的问题如下:这个元素类和什么是对象有什么关系?

Many thanks in advance

提前谢谢了

3 个解决方案

#1


1  

My guess would be - programming science book with ISBN is an object of class Book, SpecialBook and InformaticSpecialBook (in terms of instanceOf Java operator) because this is a concrete entity (at the moment we ignore the fact that books are usually printed in numbers, i.e. there are 5000 books printed with same ISBN).

我的猜测是 - 用ISBN编程科学书籍是Book,SpecialBook和InformaticSpecialBook(就instanceOf Java运算符而言)的对象,因为这是一个具体的实体(目前我们忽略了书籍通常用数字打印的事实,即有5000本书使用相同的ISBN打印。

The others are classes and maybe subclasses connected with inheritance relation - for example, SpecialBook is inherited from Book, MathSpecialBook and InformaticSpecialBook are inherited from SpecialBook.

其他是类和可能与继承关系相关的子类 - 例如,SpecialBook继承自Book,MathSpecialBook和InformaticSpecialBook继承自SpecialBook。

If my ignorance of print run is too harsh, then probably ProgrammingScienceBookISBN12345 can be a class inherited from InformaticSpecialBook.

如果我对print run的无知太苛刻,那么ProgrammingScienceBookISBN12345可能是继承自InformaticSpecialBook的类。

#2


1  

Objects are nothing but real time instances and all you have mentioned above are realtime instances, so they are called objects.Class is nothing but a logical definition of an object.

对象只是实时实例,上面提到的只是实时实例,因此它们被称为objects.Class只是对象的逻辑定义。

#3


0  

Programmatically, you can make all of them classes or objects. It's upto you to decide what you want to do.

以编程方式,您可以创建所有类或对象。这取决于你决定你想做什么。

But considering your example, Book is the parent, so, it becomes a Parent class or Abstract class or interface if you go in detail. However, other book types can be sub classes or they can be instances of Book class.

但考虑到您的示例,Book是父级,因此,如果您详细了解,它将成为Parent类或Abstract类或接口。但是,其他书籍类型可以是子类,也可以是Book类的实例。

Say "55 Horror stories" it's horror story of type Book. but it can be "55 Horror stories" is a Horror Story type Book !

说“55恐怖故事”这是Book类型的恐怖故事。但它可以是“55恐怖故事”是恐怖故事型书!

So it's upto your requirement what you want to make. Generally, all the books have same features. So, Book can be your class and other instances or Object !

因此,您的要求取决于您想做什么。通常,所有书籍都具有相同的功能。所以,Book可以是你的类和其他实例或Object!

#1


1  

My guess would be - programming science book with ISBN is an object of class Book, SpecialBook and InformaticSpecialBook (in terms of instanceOf Java operator) because this is a concrete entity (at the moment we ignore the fact that books are usually printed in numbers, i.e. there are 5000 books printed with same ISBN).

我的猜测是 - 用ISBN编程科学书籍是Book,SpecialBook和InformaticSpecialBook(就instanceOf Java运算符而言)的对象,因为这是一个具体的实体(目前我们忽略了书籍通常用数字打印的事实,即有5000本书使用相同的ISBN打印。

The others are classes and maybe subclasses connected with inheritance relation - for example, SpecialBook is inherited from Book, MathSpecialBook and InformaticSpecialBook are inherited from SpecialBook.

其他是类和可能与继承关系相关的子类 - 例如,SpecialBook继承自Book,MathSpecialBook和InformaticSpecialBook继承自SpecialBook。

If my ignorance of print run is too harsh, then probably ProgrammingScienceBookISBN12345 can be a class inherited from InformaticSpecialBook.

如果我对print run的无知太苛刻,那么ProgrammingScienceBookISBN12345可能是继承自InformaticSpecialBook的类。

#2


1  

Objects are nothing but real time instances and all you have mentioned above are realtime instances, so they are called objects.Class is nothing but a logical definition of an object.

对象只是实时实例,上面提到的只是实时实例,因此它们被称为objects.Class只是对象的逻辑定义。

#3


0  

Programmatically, you can make all of them classes or objects. It's upto you to decide what you want to do.

以编程方式,您可以创建所有类或对象。这取决于你决定你想做什么。

But considering your example, Book is the parent, so, it becomes a Parent class or Abstract class or interface if you go in detail. However, other book types can be sub classes or they can be instances of Book class.

但考虑到您的示例,Book是父级,因此,如果您详细了解,它将成为Parent类或Abstract类或接口。但是,其他书籍类型可以是子类,也可以是Book类的实例。

Say "55 Horror stories" it's horror story of type Book. but it can be "55 Horror stories" is a Horror Story type Book !

说“55恐怖故事”这是Book类型的恐怖故事。但它可以是“55恐怖故事”是恐怖故事型书!

So it's upto your requirement what you want to make. Generally, all the books have same features. So, Book can be your class and other instances or Object !

因此,您的要求取决于您想做什么。通常,所有书籍都具有相同的功能。所以,Book可以是你的类和其他实例或Object!