This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Unexpected error" Watch "Unexpected error" New topic

Unexpected error

Vinod Vinu
Ranch Hand

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



i ran 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

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

Joined: Oct 13, 2005
Posts: 38045
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: 150

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.


star chaser..
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Unexpected error
Similar Threads
array being overwritten
Getting transient variable values while deserializing
why iam able to access defualt specifier field even within a sub-class ?
basic java question...please advice
inserting record into MSAccess Table