Hi,
I hope this is correct.
1)Class A is abstract class which contains one abstract instance method math().
2)in Class B,4 static objects of class A are instantiated.
3)and for each object the abstarct math method is overridden differently.
static A a1 = new A() {
public int math() {
return x()+y(); // will return 4 + 2 = 6
}
};
static A a2 = new A() {
public int math() {
return x()-y(); // will return 4 - 2 = 2
}
};
static A a3 = new A() {
public int math() {
return x()*y(); // will return 4 * 2 = 8
}
};
static A a4 = new A() {
public int math() {
return x()/y(); // will return 4 / 2 = 2
}
};
4)print statement will give the o/p 6282
Cheers
Maady