我有以下代码.
class Test {
int i = 0;
Test() {
System.out.println(this);
System.out.println(this.i);
}
}
public class Demo extends Test {
int i = 10;
Demo() {
super();
System.out.println("calling super");
System.out.println(this);
System.out.println(this.i);
}
public static void main(String[] args) throws IOException {
Demo d = new Demo();
}
}
O/P : Demo@2e6e1408
0
calling super
Demo@2e6e1408
10
Run Code Online (Sandbox Code Playgroud)
当我执行程序并打印"this"的值时,在超类构造函数和子类构造函数中,this(地址位置)的值显示为childClassName @ someValue ..我的问题是,为什么不是我当我在超类中打印"this"的值时,得到Test的值,即Test @ someVal(Super class).. ASAIK,Super class也会在内存中有一个位置/位置,所以,为什么我没有得到Test @someValue在第一个SOP ......
PS:我知道基于引用类型(LHS)引用变量,并且基于对象类型(RHS)调用方法.
我花了一些时间来学习什么是Java Native方法,并且它们是在平台相关代码(主要是C)中实现的.
但是我在哪里可以找到Java的原生实现?例如:Thread类的sleep(long millis)方法是native.但它的实现代码在哪里?