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
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 |
Answer / mayank sharma
no answer will be possible of this question
Is This Answer Correct ? | 1 Yes | 0 No |
What is the major drawback of internal iteration over external iteration?
What is the difference between iterator and enumeration ?
Q) I have a ArrayList object, in that object i have added 5 integer values, 5 float values, 5 string values. Now question is how can delete particular type of data ( i.e all int values or all float values or string values) in that list object at a time?
What are the common uses of "this" keyword in java ?
When is the garbage collection used in Java?
What is integer parseint?
Package1 and Package2 both have a method name lets say "methodA" with different implementation. When I import both the packages in a java class how can I use both the methods?
What will be the initial value of an object reference which is defined as an instance variable?
What are the access modifiers available in java?
Is hashset ordered java?
What is a modifier?
What is the difference between keyword and identifier?