Advertisement
narimetisaigopi

class_concept

May 12th, 2021
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. void main() {
  2. var saigopi = Human();
  3. // saigopi.name = "Sai Gopi N";
  4. print("name is ${saigopi.name}");
  5. saigopi.sleep();
  6.  
  7. var myConstructor = Human.myConstuctor();
  8.  
  9. var sum = myConstructor.addTwoNumbers(190, 20);
  10.  
  11. print("In Main >> sum is $sum");
  12.  
  13. // var kelvin = Human();
  14. // kelvin.name = "Kelvin Josh";
  15. // kelvin.sleep();
  16.  
  17. var ram = Student(5035, "Flutter");
  18. // ram.sNo = 12;
  19. // print("Roll Number is : " + ram.getRollNumber().toString());
  20. print("Roll Number is : ${ram.getRollNumber()}");
  21. }
  22.  
  23. class Student {
  24. var sNo;
  25.  
  26. // Student(var rollNumber) {
  27. // sNo = rollNumber;
  28. // print("rollNumber is $sNo");
  29. // }
  30.  
  31. var name;
  32.  
  33. Student(this.sNo, this.name) {
  34. print('Name is $name');
  35. }
  36.  
  37. getRollNumber() {
  38. return sNo;
  39. }
  40. }
  41.  
  42. class Human {
  43. // properties (variables)
  44. var name;
  45. // functions/method
  46. // syntax: function_name(){}
  47. void sleep() {
  48. print('$name is sleeping');
  49. }
  50.  
  51. int addTwoNumbers(var x, var y) {
  52. // var x = 10, y = 20; static way
  53. // print('sum is ${x + y}');
  54. return x + y;
  55. }
  56.  
  57. automaticChecking() {
  58. print('i am checking the status ... ');
  59. }
  60.  
  61. // constructor
  62. Human() {
  63. print('Human constructor has created');
  64. automaticChecking();
  65. }
  66. // getters/setters
  67. // this x is age
  68. // var age;
  69.  
  70. // named constructor
  71. Human.myConstuctor() {
  72. print('Human.myConstuctor constructor has created');
  73. }
  74. }
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement