|
Java memory model subclasses
package subClass;
class ParentClass {
public void fun () {
System.out.println ( "ParentClass ---> fun ()");
}
}
class SubClass extends ParentClass {
int i = 100;
String name = new String ( "SubClass");
public void fun () {
super.fun ();
System.out.println (name + "--->" + i);
}
}
public class TestExtends {
public static void main (String args []) {
SubClass sub = new SubClass ();
sub.fun ();
}
}
1.super is a reference to the parent class, when jvm loaded subClass, the reference to the parent class (super) loaded into subclasses stack memory.
2.this is a subclass reference when jvm loaded subClass, will refer to the current object (this) is stored in its own stack memory.
3. The specific call, first look to achieve the current sub-class, and if not, to find whether there is a parent class implementation. |
|
|
|