Experiment 3
Experiment 3
In Java, a class is a fundamental building block that serves as a blueprint for creating objects.
It encapsulates data for the object, known as attributes or fields, and defines the behaviour of
the object through methods or functions. For example, a Car class might include fields for the
car's colour, model, and year, as well as methods to perform actions like driving. The class
also typically includes a constructor, a special method used to initialise new objects. An object,
then, is an instance of a class; it is created based on the class template and has its own
unique set of data that adheres to the structure defined by the class. This allows for the
creation of multiple objects from a single class, each with its own specific data but sharing the
same methods and behaviours. In this way, classes and objects enable the principles of
object-oriented programming, such as encapsulation, inheritance, and polymorphism,
facilitating code reuse and modularity.
Class Object
Output:
2. Program in Java to print the details of student using the concept of class and
object.
Code:
Anish Dharnidhar AI & DS Batch S23 Roll no : 129
Output: