定义单词“class”的最佳方法是什么?和“对象”对没有使用它们的人? [英] What's the best way to define the words "class" and "object" to someone who hasn't used them?

查看:170
本文介绍了定义单词“class”的最佳方法是什么?和“对象”对没有使用它们的人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的邻居正在参加Java简介,并请我帮助解释一些第一天的概念。我意识到,因为我每天都这样做,所以我没有初学者的想法,而且从头开始很难将这些内容联系起来。

My neighbor is taking "Intro to Java", and asked me to help explain a few of the first-day concepts. I realized that since I do this everyday, I don't have the beginner's mind, and it's hard to relate some of this stuff from scratch.

实际上并非如此我要解释的是什么是一个班级?

The one that's actually not trivial for me to explain is "what the heck is a class?"



我到目前为止最好:


Best I have so far:


  • 变量包含某种数据;一个变量可能是名字,另一个变量可能是你的体重(磅)。

  • A variable holds some kind of data; one variable might be a first name, another variable might be your weight in pounds.

方法是一个函数,它可以处理这些变量。一种方法可能会在屏幕上显示您的名字,或者告诉您应该失去多少体重以获得良好的BMI比率。

A method is a function, it does stuff, and can do stuff with those variables. A method might display your name on screen, or tell you how much weight you should lose to have a good BMI ratio.

一个对象包含变量和方法;一个对象可能代表你,第二个对象可能代表我。

An object holds both variables and methods; one object might represent you, a second object might represent me.

是一种蓝图或模板,用于描述每个对象中的方法和变量。对象是实例化的(一个实例)类;一个对象就是某种东西,而这个类只是制作这个东西的计划。

A class is kind of the blueprint or template that describes the methods and variables that will be in each object. An object is an instantiated (instance of a) class; an object is something, while the class is simply the plans to make that something.

继续这个例子,我们有一个Person对象,实例化为保存Alice的数据,另一个Person对象实例化为保存Bob的数据,另一个为Carol,依此类推。

Continuing the example, we have a Person object, which is instantiated to hold Alice's data, and another Person object instantiated to hold Bob's data, and another for Carol, and so on.


如何调整此示例以使其更有意义,和/或什么是更好的方法? 实例化这个词在这一点上感觉太重了。

How do I tune this example to make more sense, and/or what's a better approach? The word "instantiated" feels too heavy at this point.

(我认为这是一个有用的问题,但显然是主观的;标记为社区维基。)

(I think this is a useful question, but is obviously subjective; marked as community wiki.)

推荐答案

一个类和一些类实例:

维基百科主办的公共领域图片

这篇关于定义单词“class”的最佳方法是什么?和“对象”对没有使用它们的人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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