Page Stats
Visitor: 189
Java Class 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 are called methods. These fields and methods are accessed by objects. Objects in Java are created using new operator.
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.