Constant Constructor in Dart

Constant Constructor in Dart

ยท

1 min read

  • We have to remember that whenever we create Constant Constructor in Dart our all variable are must final variable , if we use instance variable in Constant Constructor at that time the variable is not Constant .

  • Const Constructor has never any body for print statement , so we write print statement in main function using object.

  • Whenever we create const constructor's object we have to use " const " keyword , also we can use " new " keyword as well , it will not affect our output.

  • 
        //Constant Constructor Constructor 
        void main()
        {
          var const_Constructor = const display(20 , 30);
          print("The value of x : ${const_Constructor.x}");
          print("The value of y : ${const_Constructor.y}");
    
        }
    
        class display
        {
           final int x;
           final int y;
    
            const display(this.x , this.y);
    
        }
    

ย