a very good explaination. May I have some suggestionfor your example so that it looks better?
change
//other code
Child child= new Child("Mark");
child.smile();
// other code, we assume we have a class Child defined somewhere else
to
//other code
Child realChild= new Child("Mark");
realChild.smile();
// other code, we assume we have a class Child defined somewhere else
-long-river(long-river);
2000-9-5{349}(#8057@0)
nullpointerexceptionAny java programmer knows that he has to create an instance of the child class. So one of the reason why getting nullpointerexception is
if you code a condition like this
if (xxx==10) {
...
}
while the complier finds that the value is null, the npex appears. Possible solution is to use
if (xxx!=null) first to avoid it.
-guest:guest;
2000-9-5{334}(#8087@0)