私はsuperが直接の親クラスオブジェクトを参照するために使用される参照変数であることを知っています。しかし、私はsuper
とthis
の両方のハッシュコードが同じであることを意味します。つまり、それらは子オブジェクトを参照しています。hashCode()は "super"と "this"で呼び出されたときに同じ結果を返すのはなぜですか?
次に、super
は親クラスオブジェクトを呼び出すためにどのように使用されますか?
サンプルコード:
class Animal{
int a;
Animal(){
System.out.println("animal constructor ");
}
}
class Dog extends Animal{
int b;
Dog(){
System.out.println("dog constructyor ");
System.out.println(this.hashCode()+" "+super.hashCode());
System.out.println(this.getClass()+" "+super.getClass());
}
}
public class Super1{
public static void main(String[] args){
Dog d=new Dog();
System.out.println(d);
}
}
また、スーパーや、この両方のクラスが同じです。どのように「スーパー」 呼び出しの親クラスオブジェクトに
と
を使用しているよりも、彼らは子オブジェクトを参照すること
返信ありがとうございます....私はこのサイトのスーパーについて読んでいます。[リンク](https://www.javatpoint.com/super-keyword)@EJP –
そのリンクは通常のグレードAのドリブンです。大規模なOracleサイトがある場合は、サードパーティのサイトを使用しないでください。 – EJP