GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  J2EE  >  Core Java
Go To First  |  Previous Question  |  Next Question 
 Core Java  |  Question 470 of 493    Print  
Implement Interface using Polymorphism
How an interface can be implemented using polymorphism?

Why multiple inheritence is not used in Java?



  
Total Answers and Comments: 5 Last Update: June 06, 2008     Asked by: adarsh01 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
April 09, 2008 03:20:17   #1  
anubandhan Member Since: April 2008   Contribution: 2    

RE: Implement Interface using Polymorphism
In multiple Inheritance,ex: class A, Class B inherited from Class A, Class C inherited from class A, Class D inherited From Class B,and Class C.in this Class D have dual copy of the methods ,datamembers defined in Class A, Vertual Function Is there in C++ but,again the pointer are not used in java. So to avoid this ambiguity, only single chain inheritance is there, not multiple inheritance.
 
Is this answer useful? Yes | No
April 14, 2008 07:36:39   #2  
abuthahir.d Member Since: January 2008   Contribution: 10    

RE: Implement Interface using Polymorphism
Multiple inheritance will cause ambiguity in Java if any two different classes have the same method.
The necessity of Multiple Inheritance is catered using Interfaces

 
Is this answer useful? Yes | No
May 28, 2008 19:35:37   #3  
rariedel Member Since: May 2008   Contribution: 8    

RE: Implement Interface using Polymorphism

The first part of this question is ill-formed. Polymorphism is a concept and a feature of many object oriented languages, including Java, that support handling multiple data types through a uniform interface. The question implies that there is something special that must be done to use polymorphism when implementing an interface. Any time an interface is implemented the implementation itself is intrinsically an application of polymorphism.

The generally accepted explanation of why Java does not support multiple inheritance is that the language designer's wanted to keep the language simple and the complexities introduced by multiple inheritance would defeat that desired simplicity.


 
Is this answer useful? Yes | No
June 01, 2008 15:49:19   #4  
Karuna Reddy Member Since: June 2007   Contribution: 40    

RE: Implement Interface using Polymorphism
interface MyInterface{ public void HiMsg(); } public class MyClass implements MyInterface{ public void HiMsg(){ System.out.println("Hi Guys"); } } Class PolyWithInterface{
 public static void main(String args[]){ 
 
      MyInterface myInterface = new MyClass();
              myInterface.HiMsg();

}
}

 
Is this answer useful? Yes | No
June 06, 2008 00:49:38   #5  
Karuna Reddy Member Since: June 2007   Contribution: 40    

RE: Implement Interface using Polymorphism

interface I1
{
     void disp();
}


class MyClass implents I1

{

        void disp("JAI SREE RAM");

}
public class TestPoly
{
    public static void main(String args[])

    {

          I1 i = new MyClass();
              i.disp();

    }
}


 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape