fahimkamal63

Dart inheritance

Oct 17th, 2021
771
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void main() {
  2.   Child obj = Child();
  3.   obj.childMethod();
  4.   obj.parentMethod();
  5.   obj.grandParentsMethods();
  6. }
  7.  
  8. class GrandParents{
  9.   void add(int a, int b){
  10.     print (a+b);
  11.   }
  12. //   void add(int a, int b, int c){
  13. //     print (a+b+c);
  14. //   }
  15.   void grandParentsMethods(){
  16.     print ("This is Grand parents.");
  17.   }
  18. }
  19.  
  20. class Parents extends GrandParents{
  21.   void parentMethod(){
  22.     print("This is Parents.");
  23.   }
  24.  
  25. }
  26.  
  27. class Child extends Parents{
  28. //   void childMethod(int a, int b){
  29. //     print (a-b);
  30. //   }
  31.   void childMethod(){
  32.     print ("This is Child.");
  33.   }
  34.   Child(){
  35.     print ("This is Constructor");
  36.   }
  37. }
RAW Paste Data