for the following code:
class Parent {
public void say(){
System.out.println("Parent");
}
}
class Child extends Parent{
public void say(){
System.out.println("Parent");
}
}
class Test {
public static void main(String[] args){
Parent p = new Child(); // What does the compiler check
p.say();
}
}
The following questions have always confused me.
1. what exacly is happening during compile time? How does the comiler know that Parent p = new Child() is a valid code as no object has been created at compile time?
2. what exactly is hapenning at runtime? How is memory allocated
3. The implicit call to parent's constructor creates an Parent Object. A child object is also created. How is it stored and how does jvm use this for method resolution.
4. Lastly, is JVM hardcoded not to ovverride static methods and variables or there is some other reason. Why can't we use Runtime objects instance method() why not runtime objects variables
Where can I read more on these topics?
Thanks