Creating classes & objects

September 10th, 2006 Admin Posted in Creating classes & objects No Comments »

Creating classes & objects

class Welcome
{
void sayHello( )
{
System.out.println(“ Welcome to you “);
}
public static void main( String [ ] args )
{
Welcome w = new Welcome ( );
w.sayHello( );
}
}

In Java,object should be created using new keyword.

Syntax :

objname =  new ( );

In the above program,
Welcome  w =  new Welcome( ) ;
statement creates object  w.

AddThis Social Bookmark Button