Search...

Saturday, December 20, 2014

What is Java? What is Class & Object in Java?

JAVA:

Java is an Object Oriented Language. That has the feature of  Object Oriented language like:

Polymorphism

Inheritance

Encapsulation

Abstraction

Classes

Objects

Instance

Method

Message Parsing 

Object - Objects have properties/states and action/behaviors.

 If we consider a real world we found many objects around us like car, dog, human etc. All these objects have properties & action. Without properties & action their is no real existence of object.


Example: If we consider a dog then its 

Properties/state is- 

  • Name 
  • Color
  •  Breed 
Action/behavior- 

  • Barking 
  • Eating
  •  Running
  •  Wagging 


                                       If we compare the S/W objects with real world object, they have similar characteristics. S/W objects also have properties & actions. 

  • Properties/states are stored as variable/field.
  • Action/behavior is shown via methods.

Class - A class is a blue print to create real world object. All the variables declare in the class definition are called instance variable & does not occupy memory until the one of the object of the class is created. 

All the method declare in a class definition are called instance method & maintain a separate copy for each new object.



public class Dog

{

String breed;

int age;

String color;

void barking()

  {

  }

void hungry()

 {

  }

void sleeping()

  {

   }

}



No comments:

Post a Comment