class Data {
int a = 5;
}
class Main {
public static void main(String[] args) {
int b=5;
data dObj = new data();
System.out.println(dObj);
System.out.println(b);
}
}
Run Code Online (Sandbox Code Playgroud)
我想知道打印对象或数字或字符串时发生了什么.
我运行上面的代码,我得到的结果为"data @ 1ae73783"for System.out.println(dObj);和"5"forSystem.out.println(b);
然后我做了调试来检查打印对象时真的发生了什么,在调试模式中调用了很多参数(比如classloader,theards)
我知道第一次打印时,值表示类名后跟地址.但是不知道在调试模式下究竟发生了什么,因为在调试模式中发生了第二次打印变量赋值,即b = 5.
请解释一下真的发生了什么?
class A {
public virtual void M() { Console.Write("A"); }
}
class B: A {
public override void M() { Console.Write("B"); }
}
class C: B {
new public virtual void M() { Console.Write("C"); }
}
class D: C {
public override void M() { Console.Write("D"); }
static void Main() {
D d = new D();
C c = d;
B b = c;
A a = b;
d.M(); c.M(); b.M(); a.M();
}
}
Run Code Online (Sandbox Code Playgroud)
我是这个概念的新手,所以详细的答案将不胜感激.