-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass.dart
More file actions
25 lines (23 loc) · 742 Bytes
/
class.dart
File metadata and controls
25 lines (23 loc) · 742 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
class Person {
//a class is a type,,,person type
String name = "";
int age = 0;
//A constructor is a method with no return type
Person(String name, [int 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
this.name = name;
this.age = age;
}
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;
person1.showOutput();
}