如何定义一个静态对象 [英] how to define a static object
本文介绍了如何定义一个静态对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好朋友:
我有一堂课,名字是
hello friends:
i have a class with name
ReceiveMsgService()
{
-----------------------
-----------------------
-----------------------
}
我正在那里做一些工作.
现在我想在其他类中创建一个ReceiveMsgService类的静态对象.
所以你能帮我如何在其他班级定义它吗?
表示静态对象..
i m performming some work there.
now i want to make a static object of ReceiveMsgService class in my other class.
so can u help me how can i define it in my other class?
mean a static object..
推荐答案
首先,静态"和对象"确实没有什么意义.
任何静态类都不能实例化.因此,您不能创建普通类的静态实例对象.
如果您将类定义为静态
例如
First of all ''static'' and ''object'' really makes little sense.
Any static class cannot be instantiated. So you cannot create a static instance object of a normal class.
If you define your class as static
e.g.
static class ReceiveMsgService()
您将可以直接访问其他类中的静态成员.
否则,您唯一的选择是创建一个实例-
ReceiveMsgService o = new ReceiveMsgService();
,然后相应地使用它.
you will be able to direcly access static members inside the other class.
Otherwise the only option you have is to create an instance -
ReceiveMsgService o = new ReceiveMsgService();
and then use it accordingly.
静态ReceiveMsgService对象= new ReceiveMsgService();
一切正常.
static ReceiveMsgService object = new ReceiveMsgService();
and it is working fine.
这篇关于如何定义一个静态对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文