aspose file tools*
The moose likes Beginning Java and the fly likes Unexpected error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Unexpected error" Watch "Unexpected error" New topic
Author

Unexpected error

Vinod Vinu
Ranch Hand

Joined: Aug 30, 2009
Posts: 217
i have created three classes in the same package as :-
Company.java

---------------------------------------
EmpInfo.java


------------------------------
Employee.java




i ran Company.java and output was :-

Employee Code : 0
Employee Name : null

Now my question is i have assigned the values also to the fields but then why the results are 0 and null ?
i have created the object of parent class and assigned the values also. Now i have created another object of its subclass and trying to print those values. Don't you think that it should print because the parent class now has values assigned to their fields in it.

please explain me in detail as i'm a beginner and want to clear my foundation base in java very seriously.

thanks in advance.

Vinod Kumar Nair
"Any fool can write code that a computer can understan. Good programmers write code that humans can understand."
Raymond Tong
Ranch Hand

Joined: Aug 15, 2010
Posts: 230
    
    2

Vinod Vijay wrote:

I have added some comments in your code.
You are doing something like saving money in your bank account, and checking the balance in your friend's account.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
And after being here for a year, you should know better than to write "unexpected error" as your thread title.
Gary Ba
Ranch Hand

Joined: Oct 23, 2009
Posts: 161

Vinod,
You created an instance of an Employee and EmpInfo. EmpInfo is an Employee. You populated the object of Employee but not the object of EmpInfo. You then printed empInfo which was never populated.

Maybe what needs to be done is Employee should have EmpInfo instead of inhereting from it.

Gary


star chaser..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unexpected error