Named Constructor In Dart - Learn Dart Programming

Поделиться
HTML-код
  • Опубликовано: 14 дек 2024

Комментарии • 10

  • @BankITOfficer
    @BankITOfficer Год назад +1

    class Car {
    String? name;
    String? color;
    var price;
    //parameterized constructor
    Car(this.name, this.color, this.price);
    void dispaly() {
    print("car name: $name");
    print("car color: $color");
    print("car price: $price");
    }
    //named constructor
    Car.newcar(this.name, this.color, [this.price = "N/A"]);
    }
    void main(List args) {
    Car c = Car("BMW", "BLACK", 100000);
    c.dispaly();
    Car car = Car.newcar("AUDI", "RED");
    car.dispaly();
    }

  • @jio-4568
    @jio-4568 Год назад

    It was so useful. Thank you))

  • @michalsaky
    @michalsaky Год назад

    in constructor you have map and then json, what it means and why itis there?
    Thank you.

  • @Lui_Catarino
    @Lui_Catarino 7 месяцев назад +1

    class Car {
    String? name;
    String? color;
    double? prize;
    Car({this.name, this.prize, this.color});
    Car.second({this.name, this.color});
    void display() {
    print('Name: $name');
    print('Color: $color');
    print('Prize: $prize');
    print('-----------------');
    if (prize == null) {
    prize = 0;
    }
    }
    }
    void main(){
    Car honda= Car(name:'honda', color: 'black', prize: 500000);
    honda.display();
    Car bmw= Car(name: 'M4', color: 'Blue', prize: 400000);
    bmw.display();
    }

  • @khubaibirfan9215
    @khubaibirfan9215 2 года назад +1

    Sir pls make videos on single ton

  • @abdurrehmanch27
    @abdurrehmanch27 2 года назад

    Level sir ji

  • @telugutechtutssudheer6212
    @telugutechtutssudheer6212 7 месяцев назад

    bro can you upload json video

  • @foxe2206
    @foxe2206 Год назад

    ty

  • @welshmanmakwara9798
    @welshmanmakwara9798 8 месяцев назад

    Did the challenge
    class Car {
    //properties
    String? name;
    String? color;
    String? price;
    //Constructor 1
    Car({required this.name, required this.color, this.price});
    // Constructor 2
    Car.other(this.name, this.color);
    //Methods
    display() {
    if (price == null) {
    price = "not stated";
    }
    print("This car is a $name");
    print("its color is $color");
    print("the price is $price");
    print("-----------------------------");
    }
    }
    void main(List args) {
    Car car1 = Car(name: "Benz", color: "white", price: "5000");
    car1.display();
    Car car2 = Car.other("BMW", "BLUE");
    car2.display();
    }

  • @yusufvinfotech3582
    @yusufvinfotech3582 Год назад

    class Car{

    // properties

    String? name;
    String? color;
    int? prize;

    //Constructor
    Car(this.name,this.color,this.prize);

    //Name Constructor
    Car.name(this.name,this.color);


    // Methods & Function
    void display(){

    if(prize==null){

    print('The car prize is $prize');
    }

    print('The car name is $name');
    print('The car color is $color');


    }

    }
    void main(){

    // 1st object 3paremeter given

    Car car=Car('Mercedes','White',5000000);
    car.display();



    // 2nd object 2paremeter given
    Car car2=Car.name('Porsche', 'Red');
    car2.display();
    }
    Is the right???