wood burning stoves 2.0
The moose likes Java in General and the fly likes AbstractMethodError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "AbstractMethodError" Watch "AbstractMethodError" New topic


Sudarshan Sreenivasan
Ranch Hand

Joined: Jun 28, 2007
Posts: 188


Can you tell me when a AbstractMethodError occurs ?? The api says

Thrown when an application tries to call an abstract method. Normally, this error is caught by the compiler; this error can only occur at run time if the definition of some class has incompatibly changed since the currently executing method was last compiled.

I need an example situation of when this can happen at runtime ?? , I can not think of a situation where this could happen, can anyone throw light on it

Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24193

Create an empty interface

interface I {}

Create a class that implements it:

class C implements I {}

Now compile them both.

Now modify the interface:

interface I { void m(); }

Compile interface I, if you like, but do not compile class C.

Now create a class which uses the interface.

Compile only class A and run it, and you'll get an AbstractMethodError. Class C has not been compiled since interface I changed, so it does not include an implementation of method m().

[Jess in Action][AskingGoodQuestions]
Consider Paul's rocket mass heater.
subject: AbstractMethodError
It's not a secret anymore!