Java OOPs Concepts In Hindi

📔 : Java 🔗

OOPs Object Oriented Programing System का ही sort form है। PHP , Java , JavaScript और C++ की तरह ही Java भी OOPs Concept को support करती है।


OOP (Object Oriented Programing) Classes और Objects पर based एक Programming Paradigm / Approach है। Simple भाषा में कहें तो OOPs (Object Oriented Programing System) Real World Entity/Object को Programming में represent करने का method / way है। और जैसा कि आप जानते हैं कि Java में सब कुछ object है। और Java programming language के through आप real world entity को programming में represent कर सकते हैं।


Real World Entity को ही Programing में Class / Object द्वारा represent किया जाता है। Entity की कुछ Properties या Behavior होता है जिसे Programing में Class variables & methods से represent किया जाता है।


तो देखा जाए अभी तक हमने variables define किये थे , वो actually class की properties थी।

what are classes and objects

simple भाषा में समझे तो class किसी real world object में define करने का blueprint है जिसे user define करता है इसलिए इसे user defined type भी कहते हैं। एक Class, properties (variables) और behavior(method) का एक collection है जो logically एक दूसरे से related होते हैं। जैसा नीचे दिए गए template में दिखाया गया है।

Class

Person

Object

Properties / variables

name, age, height, weight etc.

Behavior / Methods

eat(), speak(), run(), laugh() etc.

और class के instance को object कहते हैं या समझ सकते हैं कि classes , objects के लिए template होती हैं। जब भी किसी class का object create किया जाता है , तो object उस class के सभी variables और methods को inherit करता है , ताकि उन्हें access कर सके। हालाँकि किस variable/method को access करना है या नहीं वो हम class में decide कर सकते हैं। Well , इन सबको आप next topics में deeply पढ़ेंगे।

Java OOPs Principle

Object Oriented Programming System के कुछ important principle इस प्रकार है -

  1. Inheritance
  2. Encapsulation
  3. Abstraction
  4. Polymorphism

Java Inheritance

किसी class को या Class की properties / behavior को extend करना Inheritance कहते हैं। जिस class को extend किया गया है उसे Parent/Super Class , जिस class के द्वारा extend किया गया है उसे Child Class कहते हैं।
Extend करने पर Child Class में लगभग बो सभी properties / methods होंगे जो Parent Class में हैं।

हालाँकि Parent Class में यह define किया जा सकता है कि कौन सी properties या methods को Child Class access कर सकती है, और कौन से नहीं।

Java Encapsulation

data members को single Object में bind करना ही encapsulation कहलाता है। Encapsulation class में defined variables & methods को protect करने की protection mechanism होती है। encapsulation mechanism की help से हम data members पर अपनी need के according access restrictions define करते हैं , जिससे data को बाहर से access नहीं किया जा सके ।

Java Abstraction

किसी भी class के लिए internal implementation details को hide करना & सिर्फ Operational process show करना ही Abstraction कहते हैं। abstraction, data Encapsulation से ही implement किया जाता है। abstraction end-user को केवल वही information show करता है जिसको उसकी जरुरत है और implementation details जो hide कर देता है।

Java Polymorphism

simple भाषा में समझें तो किसी single task को different-different way /methods से perform करना ही Polymorphism कहते हैं। Basically Polymorphism दो शव्दों से मिलकर बना है , Poly(Many) & morph (Forms). यह दो type की होती है -

  1. Run Time (Method Overriding).
  2. Compile Time (Method Overloading)

java method Overriding

Parent class में define किया गया method Child Class में भी define करना ही Method Overriding कहलाता है। Basically ये scenario Inheritance के साथ perform किया जाता है।

हालाँकि इन सभी concepts के बारे में आप आगे details में examples के साथ पढ़ेंगे , फिलहाल अभी आपको OOPs Concepts का overview दिया है ताकि चीजों को अच्छी तरह से समझ पाएं।

Java Method Overloading

method overloading same method को different parameters के साथ define किया जाता है। और यही main difference है method overriding और method overloading में। method overriding में same method को same parameters के साथ child class में define किया जाता है।

Java OOPs Advantages

  • Procedural programming के comparison में OOP काफी fast और easy तो execute रहते हैं।
  • Programs का एक clear structure रहता है, जिससे code easy तो understand बना रहता है।
  • OOP की help से हम DRY (don't repeat yourself) को follow कर पाते हैं , जिससे code को easily maintain, modify और debug कर सकते हैं।

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers