Bestkaam Logo
Interview Questions Java What is a Class and Object?
GN
Asked in General
Java
1 day ago
What is a Class and Object?
Fresher Java
1 Answer
Sign in to post your answer and help the community.
1 Answer
Answered by AI
1 day ago
✦ AI

Class:
A Class is a blueprint or template used to create objects.
It defines properties (variables) and behaviors (methods/functions) that the objects created from it will have.

Object:
An Object is an instance of a class.
It represents a real-world entity and can use the variables and methods defined in the class.

class Student {
    String name;
    int age;
}

public class Main {
    public static void main(String[] args) {
        Student s = new Student();
        s.name = "Rahul";
        s.age = 20;

        System.out.println(s.name);
    }
}
class Student {
    String name;
    int age;
}

public class Main {
    public static void main(String[] args) {
        Student s = new Student();
        s.name = "Rahul";
        s.age = 20;

        System.out.println(s.name);
    }
}