Advertisement
wavec022

subclass stuff

Nov 18th, 2020 (edited)
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. subclass stuff
  2.  
  3. there can be a thing that is a subclass of two parent classes-- a Mermaid is a Fish and a Person
  4. how about a Furniture and a Vehicle? wheelchair
  5.  
  6. class Foo extends Bar implements I1,I2,I3... (this is Java)
  7.  
  8. Scala--
  9. class Foo extends Bar with T1, T2, T3...
  10. trait T1... etc etc
  11.  
  12. Which do you pick if both parents have the same method with different implementations?
  13. "overloading"
  14.  
  15. def foo(x:Int)
  16. def foo(x:Int, b:Boolean)
  17.  
  18. and that is how you tell them apart
  19.  
  20. how do you decide?
  21. - alphabetical? depth of parent? fastest? pick from first parent listed?
  22. - or, programmer must specify
  23.  
  24. ========
  25.  
  26. class Foo
  27. val x
  28. def f(): Mammal
  29. def g(x: Mammal): Unit
  30.  
  31. class Bar extends Foo
  32. def f(): Cat // this is covariance -- methods only
  33. def g(x: Animal): Unit // this is contravariance -- parameters only
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement