Posts

Showing posts with the label extends keyword

Inheritance in Java जावा में इनहेरिटेंस

Inheritance lets one class acquire properties and behaviors of another class Inheritance is a fundamental concept of object-oriented programming, where a class (child or subclass) can inherit the properties and behavior of another class (parent or superclass). Java supports inheritance using the extends keyword. This allows for code reuse , meaning we don’t have to rewrite methods and variables that already exist in the parent class. It works just like children inheriting traits from their parents. इनहेरिटेंस ऑब्जेक्ट ओरिएंटेड प्रोग्रामिंग का एक मूल सिद्धांत है, जिसमें एक क्लास (सबक्लास या चाइल्ड क्लास) किसी अन्य क्लास (सुपर क्लास या पैरेंट क्लास) के गुणों और व्यवहारों को प्राप्त करती है। जावा में extends कीवर्ड का उपयोग करके इनहेरिटेंस को लागू किया जाता है। यह कोड के पुनः उपयोग (code reuse) को संभव बनाता है। Syntax: class SubclassName extends SuperclassName { // fields and methods } 🔹 Types of Inheritance in Java Java supports the following types of inheritance: Singl...