| Author |
overiding method(own code)
|
Arjun Srivastava
Ranch Hand
Joined: Jun 23, 2010
Posts: 431
|
|
RESULT:compilation fails due to line 3
method on line 2 has been overrided ,ok
in overriding ,object type determines which method has to be invoked,so in line3 method in class B should be invoked,which is not throwing exception,i don't think line3 should be in try catch block.
Then why compilation fails?please explain the logic behind this.
|
SCJP 6 | FB : Java Certifications-Help. | India Against Corruption
|
 |
Abimaran Kugathasan
Ranch Hand
Joined: Nov 04, 2009
Posts: 2066
|
|
|
At compile time, the compiler checks the reference type, not the actual object! So, a Compilation error!
|
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
|
 |
Rajeev Rnair
Ranch Hand
Joined: Mar 22, 2010
Posts: 308
|
|
Abimaran Kugathasan wrote:At compile time, the compiler checks the reference type, not the actual object! So, a Compilation error!
Abimaran is correct. Since the compiler checks the reference type while compiling, it gives error with a.foo() because it throws Exception and it is not caught any where.
If you look closely, even if you add try catch block around line 3, it will NOT solve the issue. foo() method of Class A is still declared to throw an Exception.
So either you have to add a try/catch inside main() where a.foo() is called or you need to declare
for the code to compile.
|
SCJP6, SCWCD5, OCP-JBCD5, OCE-JWSD6 OCE-JPAD6 , OCM-JEA5 1,OCM-JEA5 2,3 - Brainbench certifications: J2EE, Java2, Java2-NonGUI, JSP, SQL2000 Admin, SQL2000 Programming , Brainbench certified Java Programmer, Computer Programmer, Web Developer, Database Administrator
|
 |
Arjun Srivastava
Ranch Hand
Joined: Jun 23, 2010
Posts: 431
|
|
thanks for the reply,tomorrow morning is my exam.really sacred.
|
 |
Abimaran Kugathasan
Ranch Hand
Joined: Nov 04, 2009
Posts: 2066
|
|
Arjun Srivastava wrote:thanks for the reply,tomorrow morning is my exam.really sacred.
Don't worry. All is well!
BTW, I've SCWCD exam tomorrow~!
|
 |
Arjun Srivastava
Ranch Hand
Joined: Jun 23, 2010
Posts: 431
|
|
Abimaran Kugathasan wrote:
Don't worry. All is well!
BTW, I've SCWCD exam tomorrow~!
yea,AAL IS WELL.
|
 |
Abimaran Kugathasan
Ranch Hand
Joined: Nov 04, 2009
Posts: 2066
|
|
|
Hey mate all is well!
|
 |
 |
|
|
subject: overiding method(own code)
|
|
|