java classes tutorial

java classes tutorial explains in detail about Classes and objects this chapter make you understand what is class and what is an object. Bodhak java tutorial will make you understand how to create a class and how to create an object.

in this chapter, you will understand how to declare the class and how o declare the object. The syntax and examples are given for better understanding.


java classes tutorial

Class :

The class is a set of attributes and operations that are performed on the attributes.

A class is a blueprint of an object

It is the model from which objects are created

A class defines the methods and types of data of an object

Creating an object from a class is called instantiation;

An object is an instance of a particular class

For example,

  1. the Account class could describe many bank accounts
  2. ram’s Savings is a particular bank account with a particular balance

Object :

An Object Oriented system is a collection of interacting Objects.

an object is an instance of a class.

An object has

  1. state –  descriptive characteristics
  2. behaviors –  what it can do (or be done to it)

For example, a particular bank account (object)

has an account number (state)

has a current balance    (state)

can be deposited into    (behavior)

can be withdrawn from (behavior)

A class represents a template for several objects that have common properties.

A class defines all the properties common to the object  –  attributes and methods.

A class is sometimes called the object’s type.

Object creation procedure:

In order to create the object, we required two things.

Declaring object

Creating object

Object Declaration

<class name> <object name>;

Declaring an object does not create an object. It simply sets up a named location in memory that stores a reference (address) to that object.

Student student1; // declares object named player

Object Creation :

<object name> = new <class name> (<arguments>);

student1 = new Student(); // creates object