Skip to content

Instantly share code, notes, and snippets.

@Hurly77
Last active April 4, 2023 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Hurly77/aeda344009fdb949f9ab7add1828d19e to your computer and use it in GitHub Desktop.
Save Hurly77/aeda344009fdb949f9ab7add1828d19e to your computer and use it in GitHub Desktop.
class Bird {
layEgg () {}
}
class FlyingBird {
fly () {}
}
class SwimmingBird extends Bird {
swim () {}
}
class Eagle extends FlyingBird {}
class Penguin extends SwimmingBird {}
const penguin = new Penguin();
penguin.swim();
penguin.layEgg();
const eagle = new Eagle();
eagle.fly();
eagle.layEgg();
@sitek94
Copy link

sitek94 commented Sep 21, 2021

Hey there 👋

Shouldn't the Penguin class learn to swim? :D

class Penguin extends SwimmingBird {}

@Hurly77
Copy link
Author

Hurly77 commented Sep 21, 2021

Hey @sitek94

Lol, you are 100% correct Idk what I was thinking, haha.
I went ahead and updated it thanks for pointing that out.

@sitek94
Copy link

sitek94 commented Sep 21, 2021

We need intellisense when writing gists haha :D

By the way, thanks for really helpful examples :)

@PetkoPetrow
Copy link

line 23: eagle.layEgg(); <== how is that even possible since class Eagle extends FlyingBird {} and FlyingBird class does not extend Bird ?

@UsmanAhri
Copy link

I think so too. It seems on line 5 it should have been like this:

class FlyingBird extends Bird {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment