Saturday, December 11, 2010

how can i create a class??

Usually when you create a project a class is generated for you automatically by java IDE ( i m using netbeans 6.9.1). But thats not all about you can make almost as many classes as u want:
for a generic class m making a class with its constructor displaying welcome message
if you want to add new class in same folder as the main class dont use identifier as public(m doing so)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class welcome{
public welcome()
{
System.out.println("Welcome to Java......................!!!!");
}
}
public class Demo
{
public static void Main(String[] args)
{
welcome w=new welcome();
}
}
*Remember classes are always like a container which contains some things and any thing belonging to class are called via its object.
*Remember
public welcome(){}
its not a method in fact it is constructor. Code in consructor execute before all when we create an object of a class thats y all initialization code are inside of constructor.

No comments:

Post a Comment