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?

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

How does the garbage collector works in java?

1093


Can inner class extend any class?

1056


Is null function in java?

1041


how can you take care of mutual exclusion using java threads? : Java thread

1048


what is thread? What are the high-level thread states? Or what are the states associated in the thread? : Java thread

984


When is an object subject to garbage collection?

1067


What is passing by reference in java?

1019


What is better - 'bit-shift a value' or 'multiply by 2'?

1191


Describe different states of a thread.

1005


What is the difference between an if statement and a switch statement?

1166


How does thread synchronization occurs inside a monitor? What levels of synchronization can you apply?

962


What is stringbuffer in java?

1060


What is the list interface?

1082


What does escaping a character mean?

1017


What does a za z0 9 mean?

1105