for example
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)
{
1) welcome w;
2) w.displayGreeting(); //generates an error of uninitialized object but the matter it has no refrence and dont know where to point.
3) welcome wel=new welcome(); //object type :welcome and refrence of:welcome
4) wel.displayGreeting();
}
}
*Remember statment 1 and 2 will not compile and elt the program run but statment 3 and 4 will behave exactly as like an normal and successful program is supposed to behave.
No comments:
Post a Comment