Sunday, July 9, 2023

Object-Oriented-Programming-Java

 Object-Oriented-Programming Language :In Simple  way

  1. Abstraction :

    • Let's suppose you want to turn on the bulb in your room. What do you do to switch on the bulb. You simply press the button and the light bulb turns on. Right? Notice that here you're only concerned with your final result, i.e., turning on the light bulb. You do not care about the circuit of the bulb or how current flows through the bulb. The point here is that you press the switch, the bulb turns on! You don't know how the bulb turned on/how the circuit is made because all these details are hidden from you. This phenomenon is known as abstraction. 
    • More formally, data abstraction is the way through which only the essential info is shown to the user, and all the internal details remain hidden from the user.
      Example :
  2. Polymorphism :

    • One entity many forms.
    • The word polymorphism comprises two words, poly which means many, and morph, which means forms.
    • In OOPs, polymorphism is the property that helps to perform a  single task in different ways.
    • Let us consider a real-life example of polymorphism. A woman at the same time can be a mother, wife, sister, daughter, etc. Here, a woman is an entity having different forms.
    • Let's take another example, a smartphone can work like a camera as well as like a calculator. So, you can see the a smartphone is an entity having different forms. Also :

  3. Encapsulation :

    • The act of putting various components together (in a capsule).
    • In java, the variables and methods are the components that are wrapped inside a single unit named class.
    • All the methods and variables of a class remain hidden from any other class.
    • A automatic cold drink vending machine is an example of encapsulation.
    • Cold drinks inside the machine are data that is wrapped inside a single unit cold drink vending machine.
  4. Inheritance :

    • The act of deriving new things from existing things.
    • In Java, one class can acquire all the properties and behaviours of other some other class
    • The class which inherits some other class is known as child class or sub class.
    • The class which is inherited is known as parent class or super class.
    • Inheritance helps us to write more efficient code because it increases the reusablity of the code.
    • Example : 
    • Rickshaw      →        E-Rickshaw
    •  Phone           →        Smart Phone

No comments: