Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. //class object and constructor
  2. //beginner level constructor
  3. void main(){
  4. //creating a object called 'jenny'
  5. Human jenny = Human(15);
  6. //now accessing method talk
  7. jenny.talk('hello world');
  8. print('i am ${jenny.height} years old');
  9.  
  10. //operation on advance constructor
  11. Human2 sam = Human2(height:10,weight:20);
  12. print('his height is ${sam.height} and ${sam.weight}');
  13. }
  14.  
  15. class Human{
  16. //properties
  17. double height;
  18. int age=1;
  19.  
  20. //constructor
  21. Human(double startingHeight){
  22. height = startingHeight;
  23. }
  24.  
  25. //methods
  26. void talk(String speak){
  27. print(speak);
  28. }
  29.  
  30. }
  31.  
  32. // advance level of constructor
  33. class Human2{
  34. double height;
  35. double weight;
  36.  
  37. //creating a constructor
  38. Human2({this.height,this.weight});
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement