java / oops中的静态变量和动态变量有什么区别? [英] What is the difference between a static variable and a dynamic variable in java/oops?

查看:179
本文介绍了java / oops中的静态变量和动态变量有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请告诉我oops或java中'静态变量'和'动态变量'之间的区别。如果可能,也可以使用它们。

解决方案

考虑一个具有静态和动态变量的类。




  • 动态变量:创建类的实例时,每个对象都有自己的动态变量副本。对于每个对象,此变量的值将不同,无论该对象中为其分配的值如何。

  • 静态变量:这些是类级变量。这些变量的值将在类的所有对象之间共享。当其中一个对象更改其值时,该值将是其他对象可用的最新值。这意味着这些是共享变量。


please some1 tell me the difference between a 'static variable' and a 'dynamic variable' in oops or in java. Also their usage if possible.

解决方案

Consider a class having static and dynamic variables.

  • Dynamic variables : When instance of the class is created, each object has its own copy of dynamic variables. Values of this variables will be different for each object, whatever the value is assigned to it in that object.
  • Static variable : These are class level variables. The value of these variables will be shared among all the objects of the class. When one of the object changes its value that will be the latest value available for other objects. That means these are the shared variables.

这篇关于java / oops中的静态变量和动态变量有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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