class A {
}
class B
{
static A a;
}
What does this mean? dose it mean i can have only instance of class A inside class B?
class A {
}
class B
{
static A a;
}
What does this mean? dose it mean i can have only instance of class A inside class B?
The number of instances of A
within B
is not determinded by static
or any other keyword, but by the definition of the member a
within class B
. So when a
is just one A
, there surely is exactly one instance of A
per B
. However if a
is declared as a list you surely have more instances.
Static
simply means that your instances of B
share the same reference to your instance of A
, so with your code you have exactly one instance of A
that can be used by any kind of B
. Moreover you do not even need an instance of B
to access that single instance of A
. However it does not mean that only one instance of A
exist within your application as other classes might create instances of A
as well.