🟣 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 करें।