class welcome{
private String greet;
public welcome()
{
greet="Welcome to Java......................!!!!";
}
public void displayGreeting()
{
System.out.println("Greeting : "+greet);
}
}
public class Demo
{
public static void Main(String[] args)
{
welcome w=new welcome(); /////now constructor will only initialize and will do nothing else
w.displayGreeting();
}
}
*This programe behave Exactly same as last one but biggest difference is that here constructor only initializes and does nothing else until
w.displayGreeing();
line called no greetings are displayed on screen.
No comments:
Post a Comment