[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.axapta.programming

Static class modifier; What is used for?

Necmi Göcek

11/7/2005 2:12:00 PM

http://msdn2.microsoft.com/library/79b...
In this link, There are some proporties of static classes but these feateres
is not valid SO what is the purpose of static keyword for class declaration.
--
_MIB_
5 Answers

Marcin Krzyzanowski

11/7/2005 2:31:00 PM

0

Necmi Göcek napisa3(a):
> http://msdn2.microsoft.com/library/79b...
> In this link, There are some proporties of static classes but these feateres
> is not valid SO what is the purpose of static keyword for class declaration.

The point here is:
"A class can be declared static, indicating that it contains only static
members. It is not possible to create instances of a static class using
the new keyword."

It's quite good explanation there, I tied understand you question, but
maybe you should give more details about you problem.

Necmi Göcek

11/7/2005 3:19:00 PM

0

Hi Marcin Krzyzanowski.
Thanks for your fast reply.
> The point here is:
> "A class can be declared static, indicating that it contains only static
> members.
Firts of all, static modifier for classes allows non-static members and
non-static methods

> It is not possible to create instances of a static class using
> the new keyword."
And static modifier for classes allows to create instance by using new
keyword. SO what is the magic for STATIC modifier for classes.

Here is an example that compiled succesfully and run without a problem.
static class MyClass
{
str nonStaticMember;
}
static void StaticMethod()
{
print "StaticMethod called!!!";
}

void NonStaticMethod()
{
print "NonStaticMethod called!!!";
}

JOB;
static void Test(Args _args)
{
MyClass _myClass;
;
_myClass = new MyClass();
_myClass.NonStaticMethod();
MyClass::StaticMethod();

pause;
}

--
_MIB_



Marcin Krzyzanowski

11/8/2005 9:29:00 AM

0

Necmi Göcek napisa3(a):
> Hi Marcin Krzyzanowski.
> Thanks for your fast reply.
>> The point here is:
>> "A class can be declared static, indicating that it contains only static
>> members.
> Firts of all, static modifier for classes allows non-static members and
> non-static methods

First of all you point to C# documentation, however this is a common
part of every object oriented language.

>> It is not possible to create instances of a static class using
>> the new keyword."
> And static modifier for classes allows to create instance by using new
> keyword. SO what is the magic for STATIC modifier for classes.

it make it static, not instance orientend. Generally you create instance
of class and call methods of this object instance. With static
classess/methods you do not have instance, methods are called directly,
not sure about X++, but sometimes (C, Java) static with variables mean
that they keep value while program is working. There is no "this"
because there is no instance.

>
> Here is an example that compiled succesfully and run without a problem.
(...)


Yeap, this is how it work with X++


Regards.

Necmi Göcek

11/8/2005 9:59:00 AM

0

Thanks for your reply,
In Java and C# static class modifier used to make classes that is EXACTLY
static (as you stated "it make it static, not instance orientend") but in
X++ static class modifier makes no difference with non static classes. I mean
we can create instance of a static class and we can use this keyword in a
static class. So what is the difference between a static class and a
non-static class in X++.
--
_MIB_

Marcin Krzyzanowski

11/8/2005 10:55:00 AM

0

Necmi Göcek napisa3(a):
> Thanks for your reply,
> In Java and C# static class modifier used to make classes that is EXACTLY
> static (as you stated "it make it static, not instance orientend") but in
> X++ static class modifier makes no difference with non static classes. I mean
> we can create instance of a static class and we can use this keyword in a
> static class. So what is the difference between a static class and a
> non-static class in X++.

yeap, I think you right, there is no difference in X++. Static keyword
before class keyword means nothing, except notice for programmer ;)


Regards