Object
In object-oriented programming, an object is an entity that has two characteristics: state and behavior. Some real-world objects include books, phones, tables, computers, etc. An object is a variable of a class type. It is the basic building block of an object-oriented programming system.
A class contains methods and data members (attributes). These methods and data members are accessed and used through an object. Therefore, an object is an instance of a class.
Example: StudentObject.java
Source Code:
public class StudentObject {
// Define the Student class
static class Student {
// Attribute
String name = "Thida";
// Method to print a message
void sayHi() {
System.out.println("Hi, I'm " + name);
}
}
public static void main(String[] args) {
// Create an object of Student
Student s = new Student();
// Call the method
s.sayHi();
}
}Result:
Watch the video:Ebook: https://softkhpc.blogspot.com/2025/05/java-programming-ebooks.html

