Home > Back-end >  Java in succession
Java in succession

Time:12-14

 
class A {
Double (double x, f double y) {
Return x + y;
}
Static int g (int n) {
Return n * n.
}
}
Class B extends A {
Double (double x, f double y) {
Double m=super f (x, y);
Return m + x * y;
}
Static int g (int n) {
Atul gawande at the int m=(n);//subclass class method how to deal with the
The return of m + n.
}
}
Public class Test5_3_3 {
Public static void main (String [] args) {
B B=new B ();
System. The out. Println (b. (10.0, 8.0));
System. The out. Println (b.g (3));
A=new B ();
System. The out. Println (a.f (10.0, 8.0));
System. The out. Println (al-qeada (3));//output: 9 (not understand)
}
}

Code as above, mark of one line of code that I think the result is " 12 ", don't know much about this to subclassing, class method is what happened?

CodePudding user response:

Static methods only belongs to the class, no object, you create A B object points to A reference, and then call is A static methods in g (), will not call in the B method, A static methods in will not be B rewrite

CodePudding user response:

1/f, reference source is A ghost reply:
static method only belongs to the class, no object, you create A B object points to A reference, and then call is A static methods in g (), and will not call in the B method, A static methods in will not be B rewrite the
thank you!
  • Related