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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

Why stringbuffer is faster than string?

1028


How do you use compareto in java?

961


Can we serialize singleton class?

1023


What are the features of junit?

1023


Write a program to reverse array in place?

1050


What java ide should I use?

974


What is the use of optional ?

1018


What is a parent class in java?

999


Can we access instance variables within static methods ?

1075


Is it possible to instantiate the abstract class?

940


whar are the draw backs of programming lang step by step in Clang and next in C++ and next and in Java nad in .Net

2083


Can we catch more than one exception in single catch block?

1032


What is the need of transient variables in Java ?

1057


How do you classify Dialog Box?

1095


Can we override private constructor in java?

953