• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Reference Variable casting ... compile Errors vs Runtime errors

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi :
can you please tell me the rule to know wheather an upcast or a downcast will produce a compile error OR a runtime error , for exemple :





i tought the it will produce "howl woof followed by an exception " BUT it produce a compile error at line 15 ..???
 
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

karim amrani wrote:
i tought the it will produce "howl woof followed by an exception " BUT it produce a compile error at line 15 ..???


welcome to ranch!!
go to edit and use code tags for writing codes.

because dog class doesn't know about the sniff() method, so it's a compiler error.
why do you think it should give a run-time exception?
 
karim amrani
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
because i dont know how to determines wich type of error it will raise ...so the MethodNotFoundException comes in my head and thought it's probably this .... that's why i asked you about A FIRM RULE to know if an error will be catched by the complier or while excution ..
thanks for the code-tag tip and Sorry for my english
 
Arjun Srivastava
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
no problem friend.
if compiler didn't able to find something that you are referring or using or some kind of syntactical mistake ,then it will gives you a compiler error.
exception will be thrown when your program satisfies the compiler needs,but some illegal behavior like illegal reference or argument you are using cause your program to stop at run time.
 
Quick! Before anybody notices! Cover it up with this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic