qinglouchangke
qinglouchangke
2021-01-25 01:52

这段代码的打印过程是怎样的,我是小白,恳求诸位大佬指点一下

  • java
package LSQ;

class SuperClass{

	  int x;

	  SuperClass(){

	    x = 3;

	    System.out.println("in SuperClass:x=" + x);

	  }

	  void doSomething(){

	    System.out.println("in SuperClass.doSomething()");

	  }

	}

	class SubClass extends SuperClass{

	  int x;

	  SubClass(){

	    super();

	    x = 5;

	    System.out.println("in SubClass:x=" + x);

	  }

	  void doSomething(){

	    super.doSomething();

	    System.out.println("in SubClass.doSomething()");

	    System.out.println("super.x=" + super.x + " sub.x=" + x);

	  }

	}

	public class Star2{

	  public static void main(String[] args){

	    SubClass subC = new SubClass();

	    subC.doSomething();

	  }

	}

 

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

3条回答