zoukankan      html  css  js  c++  java
  • this super 解释

    关于 this super 什么时候有,他们指向谁?

    书上说: this 指向自己,super指向父亲的对象,个人觉得是错误的.

    我认为 this 是一个指向自己对象的句柄,而super只是一个类句柄

     1 package chuji;
     2 
     3 class A {
     4     void A() {
     5 
     6     }
     7 
     8 }
     9 
    10 class B extends A {
    11     void foo() {
    12         System.out.println(this.getClass());
    13         System.out.println(super.getClass());
    14 
    15     }
    16 
    17 }
    18 
    19 public class super_this {
    20 
    21     /**
    22      * @param args
    23      */
    24     public static void main(String[] args) {
    25         // TODO Auto-generated method stub
    26         B b = new B();
    27         b.foo();
    28     }
    29 
    30 }

    输出结果:

    class chuji.B
    class chuji.B

    输出的结构都是B.

    this 和 super 都是指向自己的对象.

  • 相关阅读:
    JavaScript事件详解
    JavaScript事件
    十六进制转十进制原理
    java:数组复制
    java:数组扩容
    MySQL---Day2
    Pyhton学习——Day47
    MySQL---Day1
    Pyhton学习——Day46
    Someing-About-Work
  • 原文地址:https://www.cnblogs.com/ziq711/p/5374624.html
Copyright © 2011-2022 走看看