What is a class in Java?

Classes are fundamental or basic unit in Object Oriented Programming .

A class is kind of blueprint or template for objects.

Class defines variables, methods.

A class tells what type of objects we are creating.

For example take Department class tells us we can create department type objects.

We can create any number of department objects.


All programming constructs in java reside in class.

When JVM starts running it first looks for the class when we compile.

Every Java application must have at least one class and one main method.

Class starts with class keyword. A class definition must be saved in class file that has same as class name.


File name must end with .java extension.

public class FirstClass 
{public static void main(String[] args) 
{System.out.println(โ€œMy First classโ€);
}
}

To instantiate the FirstClass we use this statement
FirstClass f=new FirstClass();
f is used to refer FirstClass object


Posted

in

Tags:

Comments

Leave a Reply