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...


What are the ways of polymorphism other than Overridding &
Overloading



What are the ways of polymorphism other than Overridding & Overloading..

Answer / alka

Interface is third way to achieve polymorphism.Because when
you call a method on any interface variable then at run time
it is decided which object method to call.
Ex :
Let there is a Interface A:
public interface A
{
void display();
}

And two classes B and C implement A
class B implements A
{
display()
{
System.out.println("Class B");
}
}

class C implements A
{
display()
{
System.out.println("Class C");
}
}

Then while using interface A..see what will happen
class mainClass
{
public static void main(String args[])
{
A obj = new C();
obj.display();
obj = new B();
obj.display();
}
}

Output : Class C
Class B
So it is clear that while run/execution time it is decided
which display() method to call..i.e class B or class C display()

Is This Answer Correct ?    17 Yes 0 No

Post New Answer

More Core Java Interview Questions

What are the basic control structures?

0 Answers  


explain the classification of exception and hoew to handle the exceptions

2 Answers  


What is the null?

0 Answers  


Give any two differences between C++ and java.

0 Answers   GrapeCity,


How many bits are in a sentence?

0 Answers  


Which containers use a flowlayout as their default layout in java programming?

0 Answers  


Can i have abstract class with no abstract methods?

22 Answers   CTS,


What’s meant by anonymous class?

0 Answers  


What does n mean in java?

0 Answers  


why are there separate wait and sleep methods? : Java thread

0 Answers  


Question 6 [9] 6.1 In what situations (in general) would you use a TreeMap? (3) 6.2 In what situations (in general) would you use a HashSet to store a collection of values?

1 Answers  


What are the 5 types of research methods?

0 Answers  


Categories