interface X{
void m1();
void m2();
}

class Child2 extends Object implements X {

public void m1(){
System.out.println("Child2 M1");
}
public void m2(){
System.out.println("Child2 M2");
}

}
public class ParentChildInfterfaceDemo {

public static void main(String[] args){
X x = new Child2();
X x1 = new Child2();
x.m1();
x.m2();
x.equals(x1);
}

}
Will the above code work?
If yes? Can you please explain why the code
x.equals(x1) will work as the equals method is called on
interface reference vaiable?

Answer Posted / satish

this code is working.because of the reason is interface reference variable is store address of implemented class objects like
X x=new Child2{}
X x1=new Child2{}
above code means create two reference variables are created to interface and store address of implemented class objects.

actually equals method is using compare two strings.
but this senario
x.equals(x1) compare the two objects references .above code returns false

Is This Answer Correct ?    4 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is comparator in java?

549


What is the platform?

526


I am unable to find or learn about print command. I have a graphical program in core java in applet but i want to give print command but i have coding for that so if anyone know about this plz mail me on avdhesh_chauhan007@yahoo.co.in

1593


What are Normalization Rules? Define Normalization?

545


Is {a, n, d} a palindrome? If you are given a random string, is it a palindrome or not?

617






Which graphs are functions?

490


What is the use of singleton class?

517


Is integer immutable in java?

545


What is the use of coding?

517


Why do we need singleton?

533


What is logical variable?

505


What the difference is between execute, execute Query, execute Update?

369


What mechanism does java use for memory management?

486


How do I convert a string to an int in java?

545


What does this () mean in constructor chaining concept?

554