1. class static member static method
1) variables and functions using static keyword to achieve class level
2) static method can not access non-static members, non-static method can access static members
class Person {
// non-static properties, methods
// String name = 'John Doe';
// void show() {
// print(name);
// }
// non-static properties, methods
static String name = 'John Doe';
static void show() {
print(name);
}
}
main(){
// p = new Person ();
// print(p.name);
// p.show();
print(Person.name);
Person.show();
}
{the Person class static String name = 'John Doe'; int Age = 20 is; static void Show () { Print (name); } void printInfo () {/ * non-static method can access both static and non-static member * / / / print (name); // access static properties // print (this.age); // access non-static properties show (); // call the static method } static void printUserInfo () {static method // print (name) ; // static properties show (); // static methods //print(this.age); // static methods can not access non-static properties // this.printInfo (); // static methods can not access non-static methods // printInfo (); } } void main () { the Person new new P = the Person (); p.printInfo (); // call the non-static method Person.printUserInfo (); // call the static method }
The object operator 2.Dart
The Dart object operator:
? Conditional operator (understand)
as cast
type judgment is
.. cascade operation (put together) (remember)
1)? Conditional operator
{the Person class String name; NUM Age; the Person (this.name, this.age); void printInfo () { Print ( "$ --- $ {} {this.name this.age}"); } } void main () { // the Person p; // p .printInfo ();? // If the p-bit empty, no method invocation printInfo Person p = new Person ( 'John Doe', 20 is); ? p .printInfo (); // if p is not empty, then call printInfo method }