I have class A defined in a library:

```
 public final class A {blah}

```

And then I want to hack it somewhere using a new class B to substitute it:

```
A a = new A();  
A a = (A) new B();

```

B has all the methods and members in A, so it's actually safe to do this, and I can do it in C++. But for Java, this casting will result in an exception. So is there any workaround or hacking to do this in Java?
In addition, is there a way to hack without touching the VM?