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?

Answers were Sorted based on User's Feedback



interface X{ void m1(); void m2(); } class Child2 extends Object implements X { public v..

Answer / 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

interface X{ void m1(); void m2(); } class Child2 extends Object implements X { public v..

Answer / mayank sharma

no answer will be possible of this question

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More Core Java Interview Questions

What is contract between hashcode and equal method?

0 Answers  


What are basic keywords?

0 Answers  


When a thread is executing a synchronized method , then is it possible for the same thread to access other synchronized methods of an object ?

0 Answers  


How to remove the trailing spaces from a string?

0 Answers   Infogain,


Write a program to find the greatest of three numbers in java?

0 Answers  






what are the boundaries of jdk and jre?

0 Answers   CoreObjects,


string is immutable? right every one knows that, my question is it advantage or disadvantage making string immutable?

5 Answers   HCL,


What is the difference between replace and replace all?

0 Answers  


Explain the difference between an object-oriented programming language and object-based programming language?

0 Answers  


What are the parts of a method?

0 Answers  


How Marker Interfaces are instruct to complete the desired need ?

2 Answers  


Explain the importance of thread scheduler in java?

0 Answers  


Categories