public class test{ public static void main(String args[]){ System.out.println("Hello World!!!") ; A a = new A(6) ; a.printresult() ; B b = new B(7) ; b.printresult() ; } }
class A{ public int x, y ;
A(int i){ x = i ; sendresult() ; }
public void sendresult(){ y = x * x ; }
public void printresult(){ System.out.println(y) ; } }
class B extends A{ }
在B类中我想通过构造函数向类中传递x,并利用方法的覆盖把y = x * x改成y = x + x,但是不知道那个super是怎么用的。~~请大家帮我把B类里面的东西补全~~谢谢
----------------解决方案--------------------------------------------------------
class B extends A{
B (int i){ super(i); sendresult(); }
public void sendresult(){ y = x + x ; } }
class B is a subclass of A, in this case, if you have another method called sendresult which has the same method signiture as the one in its parent class, namely A, the one in the subclass, B, will be called first.
----------------解决方案--------------------------------------------------------