🟣 OOP  ·  Lesson 17

Classes and Objects

Classes and Objects

Class and Object

A class is a blueprint; an object is a real instance made from it. The class defines fields (data) and methods (actions).

Example

class Student {
    String name;
    int marks;
    void show() {
        System.out.println(name + ": " + marks);
    }
}

public class Main {
    public static void main(String[] args) {
        Student s1 = new Student();
        s1.name = "Aman";
        s1.marks = 88;
        s1.show();
    }
}
Aman: 88

Summary

  • A class is a blueprint with fields and methods.
  • Create an object with new; access members with the dot operator.

Class और Object

Class blueprint है; object उससे बनी असली instance। Class fields (data) और methods (actions) define करती है।

Example

class Student {
    String name;
    int marks;
    void show() {
        System.out.println(name + ": " + marks);
    }
}

public class Main {
    public static void main(String[] args) {
        Student s1 = new Student();
        s1.name = "Aman";
        s1.marks = 88;
        s1.show();
    }
}
Aman: 88

सारांश

  • Class fields और methods वाला blueprint है।
  • new से object बनाएं; dot operator से members access करें।
← Back to Java Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

\n