I have developed the below class as shown below
class Ab {
int i = 10;
static void getF() {
System.out.println("I am good");
}
}
class Hamm extends Ab {
int i = 10;
static void getF() {
System.out.println("I am good and bad boy");
}
public static void main(String[] args) {
//Hamm h = new Hamm();
// h.getF(); //Ham
Ab a = new Hamm(); //reference of parent class
//a.getF(); // Ab class
}
}
Now my query is there any scenario exisits where I am getting the variable i of class Ab but the method getF() of class Hamm, Please advise.
Declare the method to be non-static. You use it as instance method anyway. Static methods can not be overriden.
Here is a working sample:
And a link on ideone.