The concept of Class in Java

Java Class

In java, class is the template of creating objects. Class is also called logical entity. Class members are properties (fields), methods and constructors.

Like we have a class called Author. And the author may have data members like author id, firstName, lastName and a method like printAuthor(){} even an constructor. These are all called class members.

What is constructor: Constructor is one kind of method of the class that helps us to initialize the data members at time of object creation. Constructor name should be the class name without using public keyword.

Few more things, I should add here that class members can be static or non static. If the class members are static, we don't have to create object to initialize the class members.
Because static members belong to the class itself not the object of the class.

Instance variable: Variables or data members those are declared inside the class but outside the main method of the class are called instance variable. They can be static or non static. If no-static we have to create object to access them.


New keyword: Basically we use new keyword in java when we want to create of the of the class. But new keyword means to allocate the memory at run time.