lass TaskBase
{
int getStatusCode(Object obj) throws NullPointerException
{
if(obj != null ) return 1;
else return 0;
}
}
class ParallelTask extends TaskBase
{
//override getStatusCode method.
}
Option: 1 Overriding method can take String as a parameter.
String is the child of Object class. Cant' we pass subtype as parameter while overriding. If not why so. Please explain.
Thanks.
About Question com.enthuware.ets.scjp.v6.2.334 :
Moderator: admin
-
- Posts: 3
- Joined: Fri May 15, 2015 8:04 pm
- Contact:
-
- Site Admin
- Posts: 10385
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.334 :
No, you can't do that. If Java allowed that what would happen to the users of the class that try to pass it objects that are not Strings. For example,
This should have been explained in regular Java book. Which book are you following?
HTH,
Paul.
Code: Select all
void someMethod(TakeBase b)
{
b.getStatusCode(new Integer(0)); //if b refers to an object of SubClass (which overrides the getStatusCode method with String instead of Object, how will this call work??
}
...
TaskBase b = new SubClass();
somemethod(b);
HTH,
Paul.
-
- Posts: 3
- Joined: Fri May 15, 2015 8:04 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.334 :
kathy sierra.
I got my mistake now. Thanks.
I got my mistake now. Thanks.
Who is online
Users browsing this forum: No registered users and 11 guests