Why does the System.out.println(b.h + " " + b.getH()); prints the following:
Beta 44 <br/>
4 44 (notice this is in the second line)
I was expecting it to print something like this:
4 Beta 44 44 (this one is in one line)
The reason why I thought it would print this way is because we call b.h first which is 4.Then we call b.getH() which will print Beta 44 44
Here is the code:
class Baap{
int h = 4;
public int getH(){
System.out.println("Beta " + h);
return h;
}
}
class Beta extends Baap{
int h = 44;
public int getH(){
System.out.println("Beta " + h);
return h;
}
public static void main (String [] args) {
Baap b = new Beta();
System.out.println(b.h + " " + b.getH());
}
}