类和对象实例之间有什么区别? [英] What is the difference between classes and object instances?

查看:391
本文介绍了类和对象实例之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类是方法和变量在单个单元中的绑定.
对象是类的实例.

A class is a binding of methods and variables in a single unit.
An object is an instance of a class.

这些是编程书籍中类和对象的定义.我的朋友说,类是对象的蓝图.对象是蓝图的真实事物".他举了一个例子:如果 Company 是一个类,则INFOSYS,CTS和TCS等是对象.每当我想到类和对象时,这些定义都会使我感到困惑.如果channel是一个类,那么该类的对象是什么?如果说水是阶级,那阶级的对象是什么?你能澄清一下吗?

These are definitions for classes and objects in programming books. My friend said that a class is a blueprint of an object. An object is a real "thing" of a blueprint. He has given an example: if Company is a class, INFOSYS, CTS, and TCS etc are objects. Whenever I think about classes and objects, these definitions confuse me. If channel is a class, what would be objects for the class? If water is a class, what would be objects of class? Can you clarify?

推荐答案

如果channel是一个类,则Start Sports,BBC和ESPN是其对象. 如果水是一类,则以新鲜石灰水"和汤"为对象.

If channel is a class, Start Sports, BBC, and ESPN are its objects. If water is a Class, "Fresh Lime Water" and "Soup" are its objects.

尽管您可能会觉得这种解释含糊不清,但这是我能想到的答案.

Although you might find this explanation vague, this is the answer that I could think of.

您可以在这里学习和区分课程:

Here is how you can learn about and distinguish classes:

假设您有一个"CAR"课程

Say you have a class "CAR"

它的对象是现代,福特,铃木. 它将具有相同的方法,但设计会有所不同->这就是将对象和类与现实世界联系起来的方式.

Its objects are Hyundai, Ford, Suzuki. It will have the same methods but different designs -> this is how you can relate objects and classes with the real world.

这篇关于类和对象实例之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆