Static and overlay in Java
                                        
                    •
                    Java                                    
                public class B {
    static int i =1;
    public static int multiply(int a,int b)
    {
        return i;
    }
    public int multiply1(int a,int b)
    {
        return i;
    }
    public static void main(String args[])
    {
        B b = new A();
        System.out.println(b.multiply(5,2));
        System.out.println(b.multiply1(5,2));
    }
}
class A extends B
{
    static int i =8;
    public static int multiply(int a,int b)
    {
        return 5*i;
    }
    public int multiply1(int a,int b)
    {
        return 5*i;
    }
}
Solution
Calling static methods by reference is a very bad idea - it can confuse the code@ H_ 419_ 9@
B b = new A(); System.out.println(b.multiply(5,2)); System.out.println(b.multiply1(5,2));
B b = new A(); System.out.println(B.multiply(5,2)); System.out.println(B.multiply1(5,2));
                            The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
                        
                                            
                        THE END
                    
                    
                    
                                                        二维码
                        
                        
                                                
                        