Uzair Baig
Uzair Baig

Reputation: 1

confusing related to member hiding

if static method of child class is hidden by static method of parent class having the same signature, then why is my output as follows:

public class Main 
{
    public static void main(String args[])
    {
        Obcount.num_obj();
        Doing.num_obj();
        
    }
}


class Obcount{
    static int count;
    Obcount(){
        count++;
    }
    static void num_obj() {
        
        System.out.println("i am parent class");
    }
    
}

class Doing extends Obcount{
     double i;
     double j;
     Doing(double i,double j){
         this.i = i;
         this.j = j; 
     }
     void prod() {
         System.out.print(i*j);
     }
     static void num_obj() {
         System.out.print("i am child class");
     }
    
     void div() {
            System.out.println(i/j);
        }
}

The output is:

i am parent class i am child class

shdnt the second line of output be " i am parent class" as well? pls clarify

Upvotes: 0

Views: 20

Answers (0)

Related Questions