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

What are white spaces in java?

1048


What’s the difference between the methods sleep() and wait()?

1012


What does sprintf mean?

947


How can you make sure that your singleton class will always return single instance in multi-threaded environment?

1028


Can set contain duplicates?

996


What is variable argument in java?

1007


A non-static inner class may have object instances that are associated with instances of the class’s outer class. A static inner class does not have any object instances.

1017


In java, how many ways you can take input from the console?

998


Is class forname reflection?

990


Can constructor be static or final?

1093


What about main() method in java ?

1020


How do you check if a string contains only numeric digits?

1121


What is the function of java?

1008


What is strings in java?

1044


Name and explain the types of ways which are used to pass arguments in any function in java.

1079