Hi,
How i can find the difference in method overriding and overloading with regard to below program. And also how to find valid overload and valid override with regard to the below code.
class Big{
void doStuff(int x){ }
}
class Heavy extends Big{
//tell me whether below statement is valid overload /override
void doStuff(byte b){}
protected void doStuff(int x)throws Exception{}
}
public class Weighty extends Heavy{
void doStuff(int x);
//tell me whether below statement is valid overload /override
String doStuff(int x){return "hi";}
public int doStuff(int x){return 7;}
//tell me whether below statement is valid overload /override
private int doStuff(char c) throws Error{return 1;}
}
i have added comment to the code which explains my doubt. Can anyone explain the reason as well? I took the above example from ocp practice exams by K&B
Thank you campbell for your response.
How i can find the difference in method overriding and overloading with regard to below program. And also how to find valid overload and valid override with regard to the below code.
class Big{
void doStuff(int x){ }
}
class Heavy extends Big{
//tell me whether below statement is valid overload /override
void doStuff(byte b){}
protected void doStuff(int x)throws Exception{}
}
public class Weighty extends Heavy{
void doStuff(int x);
//tell me whether below statement is valid overload /override
String doStuff(int x){return "hi";}
public int doStuff(int x){return 7;}
//tell me whether below statement is valid overload /override
private int doStuff(char c) throws Error{return 1;}
}
i have added comment to the code which explains my doubt. Can anyone explain the reason as well? I took the above example from ocp practice exams by K&B
Thank you campbell for your response.