Java – Objects and Classes…

Java is an Object Oriented Language.It supports Object Oriented features like,

  • Polymorphism
  • Inheritance
  • Classes
  • Objects
  • Abstraction
  • Encapsulation
  • Overloading
  • Overriding
  • Reusability

Objects in Java:

Object Oriented concepts are implemented to match the real life entities.Object can be a man,desk,car or anything which has a

  • State
  • Identity
  • Behaviour

Classes in Java:

A class is an collection of objects which holds the properties of the objects.Its is an blue print of the objects behaviour.

Example:

A clear definition of a class would be,consider a class as a car.

  • Identity – A car has a color,number and unique body.
  • Behaviour – A car can move,move backward etc.
  • State – Car is idle,moving etc.

Creating a Class:

public Class Car

{

String carName;

int carNumber;

String carColor;

void moving();

void stop();

}

A Class can contain any number of variables,methods and objects.Here moving() and stop() are methods remaining things would fall as variables.There are types in variables we gonna have them later.

Creating an Object:

Object can hold values.It is used to match real time entities as i said earlier.Objects can be created using the ‘new’ keyword.Here the ‘new’ refers to a new memory allocation.

Object can be created in several ways.They are,

1.Declaration

2.Instantiation

3.Initialization

Declaration:

Syntax: ‘ClassName ObjectName;’

Instantiation:

Syntax: ‘ClassName ObjectName = new ClassName();’

Initialization:

Syntax: ‘ClassName ObjectName = new ClassName(“Value”);’

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s