Java Class Object - Explained with Example क्लास ऑब्जेक्ट - उदाहरण सहित

An object is a real-world entity that contains both properties (data) and behaviors (methods). In Java, an object is an instance of a class that represents its existence. For example – pen, pencil, calculator, car, or mobile. A class object can be logical or physical and it holds the following:

वास्तविक दुनिया की एक ऐसी इकाई जिसमें गुण (डेटा) और व्यवहार (क्रियाएँ) दोनों होते हैं, उसे ऑब्जेक्ट कहा जाता है। जावा में, एक ऑब्जेक्ट किसी क्लास का instance (उदाहरण) होता है, जो उस क्लास के अस्तित्व को दर्शाता है। जैसे – पेन, पेंसिल, कैलकुलेटर, कार, मोबाइल आदि। एक क्लास ऑब्जेक्ट तार्किक या वास्तविक हो सकता है जिसमें निम्न होते हैं:

Property – Represents the class's variables.

गुण (Property) – क्लास के वेरिएबल को दर्शाता है।


Behavior – Represents the class's methods.

व्यवहार (Behavior) – क्लास की मेथड को दर्शाता है।

In real life, a student is an object with properties like roll number, name, and marks, and behaviors like mark sheet generation, admit card printing, or scholarship status.

वास्तविक जीवन में एक स्टूडेंट ऑब्जेक्ट होता है, जिसके पास रोल नंबर, नाम और प्राप्तांक जैसे गुण होते हैं, और मार्कशीट बनाना, एडमिट कार्ड निकालना या स्कॉलरशिप लेना जैसे व्यवहार होते हैं।


🧰 How to Create Class Object in Java जावा में क्लास ऑब्जेक्ट कैसे बनाएं

In Java, an object of a class is created using the new keyword. 

जावा में किसी क्लास का ऑब्जेक्ट new कीवर्ड के माध्यम से बनाया जाता है।

Syntax

ClassName variable_name = new ClassName();

Example

public class Student {
  int rollno;
  String sname;
  float marks;

  void sinfo() {
    System.out.println("Roll Number: " + rollno);
    System.out.println("Name: " + sname);
    System.out.println("Marks: " + marks);
  }

  public static void main(String[] args) {
    Student s = new Student();
    s.rollno = 1;
    s.sname = "Ajay";
    s.marks = 421;
    s.sinfo();
  }
}

In the above example, the main() method creates an object s of the Student class and accesses its variables using that object.

उपरोक्त उदाहरण में main() मेथड का उपयोग Student क्लास का s नामक ऑब्जेक्ट तैयार करने के लिए किया गया है, और उस ऑब्जेक्ट के माध्यम से क्लास के वेरिएबल्स को एक्सेस किया गया है।


🛠️ Other Ways to Create Object in Java

In Java, objects can also be created using the following ways:

  • Using new keyword

  • Using newInstance() method

  • Using clone() method

  • Using Deserialization

  • Using factory() method


🛠️ जावा में ऑब्जेक्ट बनाने के अन्य तरीके

जावा में ऑब्जेक्ट निम्नलिखित तरीकों से भी बनाए जा सकते हैं:

  • new कीवर्ड का उपयोग करके

  • newInstance() मेथड के द्वारा

  • clone() मेथड के द्वारा

  • Deserialization के द्वारा

  • factory() मेथड के द्वारा

Comments

Popular posts from this blog

What is a Web Browser? वेब ब्राउज़र क्या है?

Java's Support System जावा का सहयोगी तंत्र

The Internet and Java इंटरनेट और जावा का सम्बन्ध