Avatar ·

TypeScript में extends और implements: क्या अंतर है?

सभी को नमस्ते! मैंने अभी-अभी JavaScript के बाद TypeScript सीखना शुरू किया है और दो कीवर्ड — `extends` और `implements` में उलझ गया हूँ। दोनों का उपयोग classes और interfaces के साथ काम करने के लिए होता है, लेकिन मुझे समझ नहीं आ रहा कि कब क्या उपयोग करूँ। मेरे पास एक सरल interface `Animal` है, जो बुनियादी properties और methods को परिभाषित करता है: ```typescript interface Animal { name: string; makeSound(): void; } ``` और मैं एक class `Dog` बनाना चाहता हूँ। उदाहरणों में मैंने देखा है कि `extends` और `implements` दोनों का उपयोग किया जाता है: ```typescript // विकल्प 1: implements class Dog implements Animal { name: string; constructor(name: string) { this.name = name; } makeSound() { console.log("Woof!"); } } // विकल्प 2: extends (यदि कोई base class हो) class AnimalBase { name: string; constructo