Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

Will set allow duplicates in java?

0 Answers  


String is a immutable objects . it means that string does not change........... But it will be chang......... { String s="kapil"; String s1="raj"; String s=s1; then print(.......) The String has been changed .. how it is possible and why its called immutable objects

7 Answers  


In collection sorting comparable and comparator interface will be used..but why this two interfaces required..two will work same purpose so why there are two interfaces instead of one?when to use comparator and when to use comparable?

1 Answers   Ericsson,


Why are data types important?

0 Answers  


Explain the difference between association, aggregation and inheritance relationships.

0 Answers  


What is a prefix function.write down a code to compute prefix function.

0 Answers  


How can we find the sum of two linked lists using stack in java?

0 Answers  


When is an object in the mean to garbage collection?

3 Answers  


What is the static import?

0 Answers  


If an application has multiple classes in it, is it okay to have a main method in more than one class?

0 Answers  


If circular link of two objects, then will it be garbage collected ?

3 Answers   TCS,


Is null a string or object in java?

0 Answers  


Categories