Java Constructors In Hindi – OOP’s In Hindi

Java

Java Constructors In HindiOOP’s In HindiJava Constructor Ek special Type Ka member function Hota Hai, Jo Aapne class Ke Name Jaisa Hota Hai And Java Destructor Ye Bhi Ek special type member function Hota Hai, Jo object Ko destroy Kar Deta Hai, Lekin Ham Java Destructor Ko Nhi Dekhne Wale Hai |

Also Read – Java Class Methods

Java Constructors In Hindi

Is Post Me Ham Constructor In Hindi Ke Bare Me Janne Wale Hai Wo Bhi Step By Step In Hindi |

Constructor In Java In Hindi Ka Istemal Keval OOPs Me Hi Hota Hai |

What is Java Constructor in Hindi – Java Constructor Ek special type Ka member function Hota Hai, Jo Aapne class Ke Name Jaisa Hota Hai Jis Class Ka Constructor Bana Ho, Agar Usi Class Ka Jab Object Jab Banta hai | Tab Vo Automatically Call Hota Hai |

Constructor ka koi bhi return type Nhi Hota hai | Void Bhi Return Nhi Karta Hai, Agar Koi Value Ko Initialize Karna Ho to Alag se Uska Member Function Bana Kar Use Object Se Sath Access Karta Padta Hai | Constructor Ye Kam Sirf Object banate Waqt hi kar deta hai |

Constructor ko Ham Class Ke Under And Bahar Bhi Define Kar Sakte Hai |

Also Read – Java Classes/Objects

Java me Constructor Ko Create Karne Ke Liye Class_name Ka Istemal Karna Hota Hai |

Example:

public class Main {
  
  // Create a class constructor for the Main class
  public Main() {
    x = 10;  // Set the initial value for the class attribute x
  }
  
  public static void main(String[] args){
    Main myObj = new Main(); // Create an object of class Main (This will call the constructor)
    System.out.println(myObj.x); // Print the value of x
  }
}

Output:

10

Aap Upper Diye Gaye Program Ko Dekh Sakte Hai, Hamne Isme Class Main Ko Create Kiya Hai And Uske Bad public Main() Constructor Ko Create Kiya Hai |

Java Constructor Parameters In Hindi

Parameterized Constructor Ek Aisa Constructor Hota Hai, Jiski Help Se Ham Parameter Ko Pass Karke Object Ko Initialize Kar Sakte Hai |

Example:

public class Main {
  int x;

  public Main(int y) {
    x = y;
  }

  public static void main(String[] args) {
    Main myObj = new Main(5);
    System.out.println(myObj.x);
  }
}

Hamne Class Main Create Ki Hai, And Fir Hamne Constructor Main(int y) Create Kiya Hai, Or Usme Ek Parameter Pass Kiya Hai |

Output:

5

Example 2:

public class Main {
  int birthYear;
  String personName;

  public Main(int year, String name) {
    birthYear = year;
    personName = name;
  }

  public static void main(String[] args) {
    Main myInfo = new Main(2002, "Danish Ali");
    System.out.println(myInfo.birthYear + " " + myInfo.personName);
  }
}

Output:

2002 Danish Ali

Characteristics of Constructor Function in Java In Hindi

  • Ise Hamesha Class Ke Public Section Mai Hi Declare Kiya Jata Hai |
  • Inhe Alag Se Call Karne Ki Jarurat Nhi Hoti Hai | jab Us Class Ka Object Banta Hai, To Yah Automatic Hi Call Ho Jata Hai |
  • Iska Koi Retrun Type Nhi Hota Hai |
  • Inko Inherit Nhi Kiya Ja sakta Hai |
  • Constructor Function Virtual Nhi Ho Sakta Hai |
  • Constructor Function Ko Point Bbi Nhi Kiya Ja Sakta Hai |

Friends Mujhe Umeed Hai Ki Aapko Constructor And Destrutor in Java in Hindi Ke Bare Mai 100% Jankari Ho Gayi Hogi | Agar Aapko Learn Karne Main Dikkat Aa Rahi Hai To Aap Mere Se Contact Kar Sakte Hai |

Yadi Aapne  HTML Full Course  And CSS Full Course And Python Full Course And PHP Full Course Nhi Read Kiya Hai To Aap Vah Bhi Read Kar Sakte Hai |

Leave a Reply

Your email address will not be published. Required fields are marked *