1)Que.
class ValHold{
public int i = 10;
}
public class ObParm{
public static void main(
String argv[]){
ObParm o = new ObParm();
o.amethod();
}
public void amethod(){
int i = 99;
ValHold v = new ValHold();
v.i=30;
System.out.println(v.i);
}//End of amethod
public int another(ValHold v, int i){
i=0;
v.i = 20;
ValHold vh = new ValHold();
v = vh;
System.out.println(v.i+ ","+i);
}//End of another
}
I run the program and get result (10,20),Why don't get result(10,10).I think v=vh has sent vh object's fields to v object.why when print vh.i ,it dose not print v object's i.Who know reason.
Thank you.
2)Question
Interface don't use new method
example: Runnable r=new Runnable();It;s wrong I know reason.
But following question.
interface IFace{}
class CFace implements IFace{}
class Base{}
public class ObRef extends Base{
public static void main(String argv[]){
ObRef ob = new ObRef();
Base b = new Base();
Object o1 = new Object();
IFace o2 = new CFace();//Why it can use new method
}
}
1)o1=o2;
2)b=ob;
3)ob=b;
4)o1=b;
Answer is 1,2,4.
Why 1 is correct.I compile the program.The answer is right.But I don't know reason.Who know ?
Thank you help.