Hey 'all
This is the code..
class A{
int i =1;
int f(){return i;}
class B extends A{
int i=2;
int f(){return -i;}
public class Test{
public static void main(
String arg[]){
B b=new B();
A a=(B)b;
System.out.println(a.i);//prints i of A. ie, 1
System.out.println(a.f());// prints -2
}
}
Though Iam assgining a reference of B to A a ,a is acting like declared type(i.e A type)..
Iam curious that is there any way we can change the reference type ..
thnx
rishi