-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass1.dart
More file actions
27 lines (25 loc) · 802 Bytes
/
class1.dart
File metadata and controls
27 lines (25 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class Person {
//a class is a type,,,person type
String name = "";
int age = 0;
//A constructor is a method with no return type
Person(this.name,
[this.age =
18]); //incase we do not pass in age it defaults to 18--This is called default constructor
//Constructor method is automatically called when you instantiate an object
//Shortcut for using this
void showOutput() {
print(name);
print(age);
}
}
void main(List<String> args) {
Person person1 = Person("Ruby",
22); //When you use a paranthesis after class name,,basically it will instantiate an object
//and assign that that object to person1 variable
//person1.name = "Christine";
//person1.age = 22;
Person person2 = Person("Nana", 20);
person1.showOutput();
person2.showOutput();
}