+91 81900 98289

Object-oriented Java groups the data and the actions that use that data into a class. A Student class can hold a name and a method that returns a result line. Each student you create with new is a separate object.

The class is the plan. The object is one real instance. You can have one Student class and many student objects, each with its own name.

Example

new Student("Meera") runs the constructor, stores the name, and label reads it back.

class Student { String name; Student(String name) { this.name = name; } String label() { return "Student: " + name; } } public class Oop { public static void main(String[] args) { Student s = new Student("Meera"); System.out.println(s.label()); } }
In a real project, put Student in its own file when it is public. A package-private class can share the file with the public class that contains main, which is what this short example does.