Home arrow static arrow Java Programming [Archive] - My question might sound funny!!!,but I need an answer
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - My question might sound funny!!!,but I need an answer
This topic has 7 replies on 1 page.

Posts:28
Registered: 7/2/04
My question might sound funny!!!,but I need an answer  
Jul 14, 2004 2:14 AM



 
I'am new to java,I would like to know that java doesn't support multiple inheritance,and instead it has a feature of interfaces....which again has methods which don't have thier implementation and constant variables.
Then when I implement this interface in my classes,I have to implement all the methods of the interface.
What is the role played by the interface here...how it replaces the place of multiple inheritance.
 

Posts:6,487
Registered: 5/5/04
Re: My question might sound funny!!!,but I need an answer  
Jul 14, 2004 2:19 AM (reply 1 of 7)



 
Java does not support multiple inheritance of classes. A class or interface can inherit multiple interfaces.
An interface can define methods and constants but should not be confused with a class.

I assume the question is not just theoretical. What is your specific problem.?
 

Posts:28
Registered: 7/2/04
Re: My question might sound funny!!!,but I need an answer  
Jul 14, 2004 2:31 AM (reply 2 of 7)



 
I totally agree with your answer.I understand,but how do u make use of these interfaces effectively.Can you show me an example which makes interfaces important...

 

Posts:109
Registered: 1/9/04
Re: My question might sound funny!!!,but I need an answer  
Jul 14, 2004 2:50 AM (reply 3 of 7)



 
Study ActionListener. It only has one method, so is simple to understand.
 

Posts:6,487
Registered: 5/5/04
Re: My question might sound funny!!!,but I need an answer  
Jul 14, 2004 2:53 AM (reply 4 of 7)



 
First detremine what you need a class to do.
Define an interface which defines the methods which need to be accessable to other packages.
Create a class which implements those methods. It may also have other methods but these are for 'internal' use.
Interfaces help you to define a contract that other packages can use.

In my case, I have mutliple implementation of the same interface which I can change at will (at run time in fact) without change the calling code because the caller only uses refers to the interface.

Interfaces are much more useful which you are writing non-trival sized programs, especially if you are sharing code with other developers.
 

Posts:6,487
Registered: 5/5/04
Re: My question might sound funny!!!,but I need an answer  
Jul 14, 2004 2:55 AM (reply 5 of 7)



 
Have a look at src.zip. It has the code for the standard libraries. There are a few things which are more historical than ideal but this is a good starting point.
 

Posts:28
Registered: 7/2/04
Re: My question might sound funny!!!,but I need an answer  
Jul 14, 2004 3:02 AM (reply 6 of 7)



 
That was very good explained ,,,thanks
Where can I locate src.zip which you were referring to....
 

Posts:6,487
Registered: 5/5/04
Re: My question might sound funny!!!,but I need an answer  
Jul 14, 2004 3:45 AM (reply 7 of 7)



 
It is under the JDK install directory.
Mine is at C:\j2sdk1.4.2_04\src.zip
You can unpack this and compile it in you favourite IDE.
I would suggest looking at the Map interface. This is one of the most used intrefaces and it is pretty obvious what it does.

BTW: if you still cannot see the point of defining an interface, perhaps you don't need one.
 
This topic has 7 replies on 1 page.