Core Java Tutorial

Define Java

C vs C++ vs Java

Java Virtual Machine

Java First Program

Java Data Types

Java Tokens

Java Keywords

Java Operators

Operator Precedence

Java Type Casting

Java Statement

Java If statement

Java Switch statement

Java Loops

Java Jumping Statement

Java Arrays 1D

Java Arrays 2D

Java Variable Size Array

Java Vector

Java Math Methods

Java String Methods

Java String Buffer

User-Defined Method

Java Method Overloading

Java Class & Object

Java Constructor

Java Inheritance

Java Interface

Java Packages

Java Multi-threading

Exceptional Handling

File Handling

Java Applets

Java DataBase Connectivity

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.