mei l.h. First, please check out our naming policy here at the ranch. Please change your display name. As for you question, that one little question can takes pages of explaination, depending on how detailed you want it. Here is the short answer: The first one 'parent p=new sun();' is declaring a variable named p that can be used to refernece any object that is of type parent, the new variable is then set to reference an object of type sun (this is ok because a sun is a parent. The second line 'sun s=new sun();' is declaring a variable named s that can be used to refernece any object that is of type sun, the new variable is then set to reference an object of type sun. Now your question can lead into a gazillion different directions from here, things like inheritence, polymorphism and many others others... Is there a certain part of this that you aren't clear on? Let us know what had you confused and we'll take a swing at it.
Ok, lets look at the two lines you're having a problem with. The first one: Manager m=new Employee(); // error 3 You're trying to have a Manager variable reference an Employee object. The problem here is that an Employee is not a Manager. The next line: Employee e=new Manager(); // ok 4 This is ok because a Manager is an Employee. In your last error line: String s=e.manager_method();// error 5 : can't resolve symbol??? The problem here is that there is no method in the Employee class called manager_method. You can only call the manager_method on a manager object. Even though the underlying object referenced by e is a Manager the compiler looks for the method based on the type of the variable not the object. What you could do (this is one of the grest things about polymorphism) is have the Manager class override the employee_method to do things specific to managers. Then you can call the method like this: String s=e.employee_method(); And get the functionality for managers that you provided in the Manager class. Like I said, at compile time the compiler checks to make sure there is a method with that name and signature in the class that is designated by the reference variable. The beautifull thing is that at run time it will call the correct method according to the underlying object, in this case the Manager object. This is cool because you could create a collection of Employee objects and then for each one invoke the correct methods without having to know exactly which subclass of Employee they really are. hope that helps