Classes
What is Class?
A Class is a Program Template for Creating Object, having similar Properties.
For Example: Consider the Class of Cars. There may be many cars with different names and brands but all of them will share some common properties like all of them will have 4 wheels, Speed Limit, Mileage range, etc. So here, Car is the class, and wheels, speed limits, mileage are their properties.
Class Declaration
Syntax:
Here,
Constructor is a method that need to be defined after defining a className
It is Executed automatically when a new object is created , we can use it to initialize object properties.
Methods are used as a function. There can be any number of Methods.
Example :
Here,
We have declared a class with name identity .
Then, We are using declaring a variable person and creating a new object identity , and calling a class assigned variable person and calling printDetails() method
This Method is returning a Identity String that is printing in the Console Tab.