Inheritances in Java -
I used to discuss the legacy on the Web in this example, and I'm not easy about the results, Missing important
public class A {int i = 5; Public A () {foo (); } Private zero foo () {System.out.println (i); }} Extension of public square b A {int i = 6;} Expansion of public square cb {int i = 7; Public zero foo () {System.out.println ("C's foo"); Println (super.i); }} I am trying to figure out what the following command is happening: cc = new c (); System.out.println (CI); I know that when we make a new example of C , we approach for the creation of A and B, then we will be A () - (Question 1) Is i (AK) being started on the way? Now we need to call the foo () - (question 2) - consider foo () as a code of foo () ? What else would be if the foo () in B? So it was considered as an override and operated by foo () of C? As far as I know, there is no override related to local characters. How is it System.out.println (c.i) 7 and 5? It should not be the father's i ? EDIT: My question is not which FU and I will be used when I use C, this is what happens during these two specific orders that it is obvious that AKFU Was used and not of C.
Thank you very much.
three i variables here completely Any use used by any statement is free at compile-time - there is no polymorphism in it. Therefore, the value of the variable declared in euf () will always be printed in A . Note that these are not local by variables - they are examples variables. When you print the ci , the variable uses the declared variable in because c is compiled-time Type is C . If you type, you can see it: cc = new C (); AA = C; Bb = c; Println (a.i); // 5 - Variable declared in a System.out.println (BI); // 6 - variable B declared in System.out.println (c.i); // 7-variable declares in C Note that such a thing in a well-written program is almost never a problem, because the variable should be private.
Comments
Post a Comment