Ad

Java Classes and Object

Everything in Java is a class or a part of a class. Class is a user-defined data type that provides a convenient method for packing together a group of logically related data items and functions that work on them. In Java, the data items are called fields and the functions inside class are called methods. These fields and methods are accessed by objects. Objects in Java are created using new keyword.

Syntax to declare a class

class <ClassName>
{	
    [fields declaration];
    [method declaration];
}

Syntax to create object of a class

ClassName objectname; // declare
objectname = new ClassName(); //instantiate.
ClassName objectname = new ClassName(); //same as above.