classes dart code example
Example 1: class in dart
class class_name {
}
Example 2: dart ?? operator
int val1;
final int val2 = 20;
console.log(val1 ?? val2);
----------------------------------
final int val1 = 30;
final int val2 = 20;
console.log(val1 ?? val2);
Example 3: with keyword in dart
mixin Human {
String name;
int age;
void about();
}
class Doctor with Human {
String specialization;
Doctor(String doctorName, int doctorAge, String specialization) {
name = doctorName;
age = doctorAge;
this.specialization = specialization;
}
void about() {
print('$name is $age years old. He is $specialization specialist.');
}
}
void main() {
Doctor doctor = Doctor("Harish Chandra", 54, 'child');
print(doctor.name);
print(doctor.age);
doctor.about();
}
Example 4: dart class
void main(){
var myDog = Dog();
myDog.breed = 'Poodle';
myDog.name = 'Jack';
myDog.color = 'Brown';
print(myDog.breed);
print(myDog.name);
print(myDog.color);
}
class Dog{
String breed;
String name;
String color;
}