This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

overiding method(own code)

 
Arjun Srivastava
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At compile time, the compiler checks the reference type, not the actual object! So, a Compilation error!
 
Rajeev Rnair
Ranch Hand
Posts: 308
Java Linux Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Arjun Srivastava
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply,tomorrow morning is my exam.really sacred.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 432
Eclipse IDE Firefox Browser Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abimaran Kugathasan wrote:
Don't worry. All is well!
BTW, I've SCWCD exam tomorrow~!

yea,AAL IS WELL.
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey mate all is well!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic