Suppose we have two classes:
Grade A:
import java.io.IOException; public class A { public void test() throws IOException{ System.out.println("test in A"); } }
Grade B:
import java.io.IOException; public class B extends A { @Override public void test() throws Exception{ System.out.println("test in B"); } }
This gives a compiler error, and I would like to know the reason for this. I can get the answer myself, but this is not completely scientific, but partially logical.
I wrote a blog post in Azerbaijani . When I wrote a blog, I was stuck in the download process.
Please be careful with quotation marks:
I think that when the compiler reads class B, it loads the headers of the header methods A and methods B. And when you call test A, the JVM calls test A, but as a test for calls to body B, and at this time we will have this method:
public void test() throws IOException{
Is the process really ongoing, like what I wrote above?
Download question headers I'm stuck here. How does the binding process work? I can not determine the background
A a = new B(); // When the compiler converts this line into bytecode // does it loads of method headers of A and method // body of B a.test()
calls a class B test. I know logically, but I cannot understand at the compiler level, binding the process.
source share