Unusual behaviour of reference pointer
Can somebody explain me, why the value of c.getI() is not changed from "100" to "sdkf"? Since equating two objects will actually make the two references point to the same memory location? This is some strange behaviour in java? I am new to java and want to know why this peculiar thing is happening?
publicabstractclass Interfac
{
String i="10";
}
class Aextends Interfac
{
A()
{
i ="100";
}
}
class Bextends Interfac
{
B()
{
i ="200";
}
}
class C
{
A a ;
C()
{
a =new A();
}
public Interfac getInterfac()
{
return a;
}
public String getI()
{
return a.i;
}
}
publicclass Main{
publicstaticvoid main(String[] args)
{
A a =new A();
B b =new B();
b.i="sdkf";
C c =new C();
Interfac i1 = c.getInterfac();
i1 = b;
System.out.println(i1.i +":" + c.getI());
//System.out.println("hashcodes: " + i1.hashCode() + " b: " + b.hashCode());
}
}

