Skip to content

Commit

Permalink
added js code
Browse files Browse the repository at this point in the history
  • Loading branch information
AE-Hertz authored Oct 18, 2024
1 parent b0d0cbd commit 6986a02
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/programming-fundamentals/OOPS/oops-05.md
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,21 @@ public class Main {
<summary><strong>JavaScript Code</strong></summary>

```js
class Animal {
sound() { // Base class method
console.log("Animal sound");
}
}

class Dog extends Animal {
sound() { // Override method
console.log("Woof!");
}
}

// Main code
const animal = new Dog(); // Reference to base class
animal.sound(); // Calls Dog's sound method, Output: Woof!
```
</details>

Expand Down

0 comments on commit 6986a02

Please sign in to comment.