JAVA Class vs Object vs Instance

转载 2016年06月01日 17:09:52

In OO Programming, we often hear of terms like “Class”, “Object” and “Instance”; but what actually is a Class / Object / Instance?

In short, An object is a software bundle of related state and behavior. A class is a blueprint or prototype from which objects are created. An instance is a single and unique unit of a class.

Example, we have a blueprint (class) represents student (object) with fields like name, age, course (class member). And we have 2 students here, Foo and Bob. So, Foo and Bob is 2 different instances of the class (Student class) that represent object (Student people).

Let me go into details…

Object
Real world objects shares 2 main characteristics, state and behavior. Human have state (name, age) and behavior (running, sleeping). Car have state (current speed, current gear) and state (applying brake, changing gear). Software objects are conceptually similar to real-world objects: they too consist of state and related behavior. An object stores its state in fields and exposes its behavior through methods.

Class
Class is a “template” / “blueprint” that is used to create objects. Basically, a class will consists of field, static field, method, static method and constructor. Field is used to hold the state of the class (eg: name of Student object). Method is used to represent the behavior of the class (eg: how a Student object going to stand-up). Constructor is used to create a new Instance of the Class.

Instance
An instance is a unique copy of a Class that representing an Object. When a new instance of a class is created, the JVM will allocate a room of memory for that class instance.

相关文章推荐

[Ruby笔记]28.Ruby @@class_variables 类变量 vs @instance_variable 实例变量

@@class_variablesTestCase 想象这样一个场景,一次小班授课,参加的学生有A B C 三人 ,这时候老师开始提问了,我们使用类Student 记录 : 到场的学生名单; 每人...

java axis调用cxf 的坑object is not an instance of declaring class while invoking public

简单说一下出错的场景,项目需要为别人系统开放webservice,于是在springmvc框架下集成cxf开发webservice接口,网上教程一大堆,小有波折,参考的 https://my.osc...

Java abstract class vs interface

前言abstract class和interface都是java用来描述抽象体的,不知道是否有同学跟我一样对这两者的语法层面的区别以及如何选择这两者还存在着疑惑,反正接下来,让我详细介绍一下abstr...

Capture CIS : Instance Vs Occurrences

用OrCAD设计原理图必须理解两个概念instance 和 occurrences。对于元件放置、替换、修改属性等很多操作都和这两个概念有关。   抛开抽象的说明,我们用实例说明他们的区别。假如你...
  • ugface
  • ugface
  • 2017年03月27日 08:48
  • 74

Another method get instance of JAVA Object

Another method get instance of JAVA Object

JNI DETECTED ERROR IN APPLICATION: can't call void XXX on instance of java.lang.Class <XXX>解决方案

最近在做一个JNI项目———C回调Java代码的地方出现了如下一个错误:JNI DETECTED ERROR IN APPLICATION: can't call void com.crycheck....

VS2013中Winform导出Excel文件时报“object”未包含“get_Range”的定义解决方法

在VS中调用COM Interop DLL操作Excel通过get_Range去获取Range时,会发生Object does not contain a definition for get_Ran...

Redis 存储图片 [base64/url/path]vs[object]

一、base64图片编解码  基本流程:从网络获取下载一张图片,然后base64编码,再base64解码,存到本地E盘根目录下。      import java.awt.image.Buffer...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:JAVA Class vs Object vs Instance
举报原因:
原因补充:

(最多只允许输入30个字)