Creating Objects java In Hindi

Creating Objects java In Hindi

जावा ऑब्जेक्ट ओरिएंटेड प्रोग्रामिंग में ऑब्जेक्ट्स क्लास के इंस्टेंस या ऑब्जेक्ट क्रिएट की जाने वाली क्लास स्ट्रक्चर या वेरिएबल एलिमेंट होते हैं। जावा यूजर जब क्लास प्रोग्राम में कोई नया क्लास ऑब्जेक्ट क्रिएट करते हैं. तो जावा यूजर उस क्लास के लिए एक रियल क्लास का नया इंस्टेंस ऑब्जेक्ट क्रिएट कर रहे होते हैं. जहा उस क्लास ऑब्जेक्ट में अपने कस्टम डाटा टाइप डेटा फ़ील्ड्स और क्लास बिहेवियर मेथड्स यूजर डिफाइन होते है।

Creating Objects java In Hindi

Steps to create a new object in Java programming.

  • Define a class – यह जावा प्रोगाम में एक नई क्लास ऑब्जेक्ट्स क्रिएट करने के लिए एक फॉउण्डेशनल स्ट्रक्चर कांसेप्ट की तरह काम करता है।
  • Use the new keyword – जावा क्लास प्रोगाम में new कीवर्ड का यूज़ नए क्लास ऑब्जेक्ट इंस्टेंस क्रिएट करने में किया जाता है।
  • Call a constructor – जब जावा यूजर मौजूदा क्लास में कोई क्लास ऑब्जेक्ट क्रिएट करते हैं, तो क्रिएटेड क्लास ऑब्जेक्ट को इनिशियलाइज़ करने के लिए क्लास में क्रिएटेड क्लास कंस्ट्रक्टर को कॉल करने में इसका यूज़ किया जाता है।

Syntax for creating a new object in a Java class.

ClassName objectName = new ClassName();

Example of creating a new class object in Java programming.

यहाँ हम एक एम्प्लॉई नाम से एक नई क्लास प्रोग्राम क्रिएट करते है, जो emp_name, age, और salary जैसे एम्प्लॉई क्लास एट्रिब्यूट्स के साथ एक एम्प्लॉई डाटा को रिप्रेजेंट करती है। इसके बाद हम यहाँ एम्प्लॉई क्लास के लिए नए ऑब्जेक्ट क्रिएट करेंगे।

public class Employee {

    // here we set employee class Fields with its data type

    String emp_name;

    String age;

    int salary;

    String address;

    // employee class Constructor, Initialize the class object

    public Employee(String emp_name, String age, String address, int salary) {

        this.emp_name = emp_name;        // here we Assign the emp_name of the employee class

        this.age = age;      // here we Assign the age of the employee class

        this.address = address;        // here we Assign the address of the employee class

        this.salary = salary;        // here we Assign the salary of the employee class

       }

    // Method to display employee class element

    public void empInfo() {

        System.out.println(“\n Employee emp_name is – ” + emp_name);

        System.out.println(“\n Employee age is – ” + age);

        System.out.println(“\n Employee address is – ” + address);

        System.out.println(“\n Employee join Year is – ” + salary);

    }

    // here we create a Main method to create employee class objects

    public static void main(String[] args) {

        // Creating an object of the Employee class

        Employee myEmployee = new Employee(“Bhavishi Deora”, “21”, “New Delhi”, 2022);

        // Creating another object of the Employee class

        Employee newEmployee = new Employee(“Siddhi Deora”, “19”, “Mumbai”, 2024);

        // Calling the method to display details of each employee

        myEmployee.empInfo();

        newEmployee.empInfo();

    }

}

Explanation of creating a new class object.

Class definition (employee).

  • Employee class has four fields यहाँ एम्प्लॉई क्लास में emp_name, age, salary, और address क्लास फील्ड है. जो एम्प्लॉई क्लास के एट्रिब्यूट्स को रिप्रेजेंट करते हैं।
  • एम्प्लॉई क्लास में जब कोई नया Employee ऑब्जेक्ट क्रिएट होता है, तो एम्प्लॉई कंस्ट्रक्टर Employee(String emp_name, String age, String address, int salary) फ़ील्ड्स को इनिशियलाइज़ करता है।
  • यहाँ मेथड empInfo() एम्प्लॉई क्लास की डिटेल्स इनफार्मेशन को प्रिंट करता है।

Creating new objects in the Employee class.

Employee myEmployee = new Employee(“Bhavishi Deora”, “21”, “New Delhi”, 2022) Employee टाइप का एक नया ऑब्जेक्ट myEmployee क्रिएट करता है, और इसे emp_name, age, address, salary के लिए क्रमश, “Bhavishi Deora”, “21”, “New Delhi”, 2022 क्लास ऑब्जेक्ट वैल्यूज़ के साथ इनिशियलाइज़ करता है।

Employee newEmployee = new Employee(“Siddhi Deora”, “19”, “Mumbai”, 2024); अलग-अलग वैल्यूज़ के साथ एक और ऑब्जेक्ट newEmployee क्लास ऑब्जेक्ट को क्रिएट करता है।

Calling methods on the Employee class object.

myEmployee.empInfo(); myEmployee ऑब्जेक्ट पर empInfo मेथड को कॉल करता है, और उसकी डिटेल्स को कंसोल स्क्रीन पर प्रिंट करता है।

newEmployee.empInfo(); newEmployee ऑब्जेक्ट के लिए भी यही प्रोसेस करता है।

Things to remember when creating a new object in a Java class.

Creating a Java Class Object.

  • जावा क्लास में किसी यूजर डिफाइन क्लास का ऑब्जेक्ट क्रिएट करने के लिए, new कीवर्ड के बाद क्लास कंस्ट्रक्टर मेथड को यूज़ करें।
  • जावा प्रोग्राम में नया कंस्ट्रक्टर ऑब्जेक्ट के एट्रिब्यूट्स को इनिशियलाइज़ करने के लिए रेस्पोंसिबल होता है।

Accessing new fields and methods in a class object.

  • जावा प्रोग्राम में यूजर . ऑपरेटर का यूज़ करके क्लास ऑब्जेक्ट के फ़ील्ड्स और मेथड्स को एक्सेस और मैनेज कर सकते हैं. जैसे, myEmployee.empInfo() या newEmployee.empInfo() क्लास फील्ड को एक्सेस कर सकते है।

Creating Multiple Objects in a Java Class.

जावा प्रोग्रामर एक ही क्लास से जितने चाहें उतने नए क्लास ऑब्जेक्ट्स क्रिएट कर सकते हैं। हर क्लास क्रिएटेड ऑब्जेक्ट के पास अपने क्लास फ़ील्ड्स और कालिंग मेथड्स की कॉपी होती है।

Java Class Constructor Overloading Method.

जावा प्रोग्रामर मल्टीप्ल अलग-अलग वेरिएबल पैरामीटर्स के साथ एक क्लास में कई यूजर डिफाइन कंस्ट्रक्टर्स क्रिएट या डिफाइन कर सकते हैं। इस प्रोसेस को कंस्ट्रक्टर ओवरलोडिंग के रूप में जाना जाता हैं।

Example of Java class constructor overloading.

public class Employee {

  // here we set employee class Fields with its data type

    String emp_name;

    String age;

    int salary;

    // create Constructor with variable parameters

    public Employee(String emp_name, String age, int salary) {

        this.emp_name = emp_name;

        this.age = age;

        this.salary = salary;

    }

    // create Constructor with default user define values

    public Employee() {

        this.emp_name = “Unknown”;

        this.age = “not define”;

        this.salary = 000;

    }

    // Method to display employee class element

    public void empInfo() {

        System.out.println(“Employee Name is – ” + emp_name);

        System.out.println(“Employee Age is – ” + age);

        System.out.println(“Employee Salary is – ” + salary);

    }

    public static void main(String[] args) {

        // Creating an object of the Employee class

        Employee myEmployee = new Employee(“Bhavishi Deora”, “21”, 2022);

        // her         e we Creating an object using the default constructor

        Employee defaultemployee = new Employee();

        myEmployee.empInfo();   // here it Display myEmployee details

        defaultemployee.empInfo(); // here it Display defaultemployee details

    }

}

Java class constructor overloading explanation.

  • यहाँ इस एक्साम्प्ल में, आपके के पास दो क्लास कंस्ट्रक्टर डिफाइन हैं. जो एक स्पेसिफिक एम्प्लॉई क्लास वैल्यू के साथ क्लास फ़ील्ड को इनिशियलाइज़ करता है, और एक दूसरी क्लास है, जो की एक डिफ़ॉल्ट क्लास एलिमेंट वैल्यू को असाइन कर डिस्प्ले करता है।

Leave a Reply