class A{
public int x;
A(int x){
this.x=x;
}
}
class B extends A{
public int y;
B(int x,int y){
super(x);
this.y=y;
}
int s=x+y;
public void sum(){
System.out.println("Sum is :"+s);
}
}
public class Inheritance_2 {
public static void main(String[] args) {
B obj =new B(20,30);
obj.sum();
}
}
In this code, i wanna know why my sum is not 50 when I use s=x+y
and print s?
But when I print (x+y)
directly it gives the accurate result as 50.