Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void main() {
- var saigopi = Human();
- // saigopi.name = "Sai Gopi N";
- print("name is ${saigopi.name}");
- saigopi.sleep();
- var myConstructor = Human.myConstuctor();
- var sum = myConstructor.addTwoNumbers(190, 20);
- print("In Main >> sum is $sum");
- // var kelvin = Human();
- // kelvin.name = "Kelvin Josh";
- // kelvin.sleep();
- var ram = Student(5035, "Flutter");
- // ram.sNo = 12;
- // print("Roll Number is : " + ram.getRollNumber().toString());
- print("Roll Number is : ${ram.getRollNumber()}");
- }
- class Student {
- var sNo;
- // Student(var rollNumber) {
- // sNo = rollNumber;
- // print("rollNumber is $sNo");
- // }
- var name;
- Student(this.sNo, this.name) {
- print('Name is $name');
- }
- getRollNumber() {
- return sNo;
- }
- }
- class Human {
- // properties (variables)
- var name;
- // functions/method
- // syntax: function_name(){}
- void sleep() {
- print('$name is sleeping');
- }
- int addTwoNumbers(var x, var y) {
- // var x = 10, y = 20; static way
- // print('sum is ${x + y}');
- return x + y;
- }
- automaticChecking() {
- print('i am checking the status ... ');
- }
- // constructor
- Human() {
- print('Human constructor has created');
- automaticChecking();
- }
- // getters/setters
- // this x is age
- // var age;
- // named constructor
- Human.myConstuctor() {
- print('Human.myConstuctor constructor has created');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement