Interesting static

xiaoxiao2021-03-06  23

Static property

VAR ddd1 = new widget ();

Trace (ddd1.widgetcount);

//out.print:undefined

// ** Unable to access WidgetCount by instance properties

Trace (widget.widgetcount);

//out.print: 1

// ** Access to "Class Name. Static Properties"

VAR DDD2 = New Widget ();

Trace (widget.widgetcount);

//out.print: 2

VAR DDD3 = New Widget ();

Trace (widget.widgetcount);

//out.print:3

VAR DDD4 = New Widget ();

Trace (widget.widgetcount);

//out.print:4

Widget.widgetcount = 110;

Trace (widget.widgetcount);

//out.print:110

// ** Static attributes can still be rewritten

DDD5 = New Subwidget ();

//out.print:Creating Subwidget # 111

Trace (widget.widgetcount);

//out.print:111

// *** Description Creating a subclass inherits the constructor of the superclass

/ **

It can be understood "If you don't have the call to the call to the SUPER () in the constructor,

The compiler will automatically generate the call to the first statement of the function to which the direct superclass of the parameters is automatically included. "

* /

VAR DDD6 = New Widget ();

Trace (widget.widgetcount);

//out.print:111

VAR DDD7 = New Widget ();

Trace (widget.widgetcount);

//out.print:112

Static method

Class stat Arttest {

VAR name = "TED";

Static function getname () {

Var local_name = name;

// Error! Instance variables cannot be accessed in a static function.

}

}

//

The "class (static) method can only access the class (static) attribute, without accessing instance properties

"

转载请注明原文地址:https://www.9cbs.com/read-81032.html

New Post(0)