Solved

implimenting interface methods

Posted on 2006-11-23
7
223 Views
Last Modified: 2008-02-01
hi experts

if i have  5 methods in an interface , in my implimentation class do i have to impliment all the 5 methods of that interface?
or can i impliment less than 5

thanks
J
0
Comment
Question by:jaggernat
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 14

Assisted Solution

by:hoomanv
hoomanv earned 35 total points
ID: 18004474
If you don't implement all of them, your class becomes abstract and you wont be able to create a complete instance
0
 
LVL 10

Author Comment

by:jaggernat
ID: 18004495
so do u think i should impliment all 5 methods?
0
 
LVL 12

Accepted Solution

by:
enachemc earned 65 total points
ID: 18004515
yes, this is the point of interfaces. You must implement all methods. If you provide an empty implementation of a method, just throw an uncked exception (NotSupported, NotImplemented) ...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 10

Expert Comment

by:ADSLMark
ID: 18004522
Yes, although for some java interfaces there are adapters, from which you can extend. These implement the interface in a default way. For example:

class WListener extends WindowsAdapter implements WindowListener

Now you can override only those methods that you want to implement.

Notice that this requires an adapter class. Other solution is as sketch by hoomanv.

Mark
0
 
LVL 10

Author Comment

by:jaggernat
ID: 18004533
>>>If you provide an empty implementation of a method, just throw an uncked exception (NotSupported, NotImplemented)

what is uncked exception?

thanks
0
 
LVL 12

Expert Comment

by:enachemc
ID: 18004575
an exception that you do not have to declare that you throw and you are not obligated to catch.

http://www.javapractices.com/Topic129.cjp
0
 
LVL 10

Author Comment

by:jaggernat
ID: 18004590
thanks
0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
The viewer will learn how to implement Singleton Design Pattern in Java.

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question