-
Notifications
You must be signed in to change notification settings - Fork 0
/
advanced_oop.dart
58 lines (50 loc) · 1.21 KB
/
advanced_oop.dart
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Student class
class Student {
String name;
int age;
int gradeLevel;
// Constructor
Student(this.name, this.age, this.gradeLevel);
// Method to print student's information
void printStudentInfo() {
print('Student Information:');
print('Name: $name');
print('Age: $age');
print('Grade Level: $gradeLevel');
}
}
// Teacher class
class Teacher {
String name;
int age;
String subject;
// Constructor
Teacher(this.name, this.age, this.subject);
// Method to print teacher's information
void printTeacherInfo() {
print('Teacher Information:');
print('Name: $name');
print('Age: $age');
print('Subject: $subject');
}
}
// Third class to create student and teacher objects
class School {
void printInformation() {
// Create student object
Student student = Student('John Doe', 15, 9);
// Create teacher object
Teacher teacher = Teacher('Jane Smith', 35, 'Mathematics');
// Print student information
student.printStudentInfo();
print('\n');
// Print teacher information
teacher.printTeacherInfo();
}
}
void main() {
// Create school object
School school = School();
// Call method to print information
school.printInformation();
}