Tuesday, October 4, 2011

Method

Method is used to show the behavior of the object.

Example of Human class:

class Human
{
Human()
{
System.out.println("I am Human");
}
Human(int a)
{
System.out.println("I am Human"+" "+a);
}
void sing()
{
System.out.println("I can sing");
}
void play()
{
System.out.println("I play cricket");
}
public static void main(String ar[])
{
Human h=new Human();
h.sing(); h.play();
Human h1=new Human();
h1.sing();
Human h2=new Human(10);
h2.play();
}
}


No comments:

Post a Comment