📄 root.java
字号:
package dynamic_model;
/** A class that calls some methods to show the stacking of activation records. */
public class Root
{
public static void main(String[] arg)
{
B b;
C c = new C();
b = c;
b.rb(b.x);
}
}
/** A class with two instance variables, a constructor, and a method. */
class A
{
public double w1, w2;
/** Constructor for the class. */
public A()
{
w1 = 1.1;
w2 = 1.2;
}
/** A method that creates an object of type D, calls a
method on the object, and then returns the object. */
public D ra(D pa)
{
D dVar = new D(3);
dVar.rd(pa);
return dVar;
}
}
/** Descendant of A that adds an instance variable x and a method rb. */
class B extends A
{
public D x;
/** Constructor of B. Since the constructor is empty, it can be
removed without affecting the program. */
public B()
{
// use the default initialization
}
/** Initializes a local variable and calls a method inherited from A. */
public void rb(D pb)
{
int intVar = 1;
x = ra(pb);
}
}
/** A descendant of B that adds instance variable y and a constructor that
initializes the instance variables. */
class C extends B
{
public int y;
/** Set the instance variables, including those inherited. */
public C()
{
w1 = 3.1;
y = 2;
x = new D(y);
w2 = 3.2;
}
}
/** A class with a constructor to initialize the instance variables and a method
to cause a run-time error. */
class D
{
public int z;
/** Constructor of the class D. */
public D(int x)
{
z = x;
}
public void rd(D pb)
{
z = z / 0;
System.out.println(z);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -