•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 384,018 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,233 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Well any Java programmer knows that a Java Interface only allows declaration of methods. You cannot define the methods inside interfaces.
Yet if somebody like me wants you to define a method in interface and wants the program gets compiled and runs successfully, what would you do?
Well the answer is Inner Classes in Java. Through Inner classes, you can define a method in interfaces and run your programs.
Here's what you need to do:
Yet if somebody like me wants you to define a method in interface and wants the program gets compiled and runs successfully, what would you do?
Well the answer is Inner Classes in Java. Through Inner classes, you can define a method in interfaces and run your programs.
Here's what you need to do:
public interface IMain{ public class Main{ public static void main(String [] args){ System.out.println("The main is defined inside an Interface". Don't believe me? Look at the source.. Geee.."); } } } compile the program using javac. run the program by typing java IMain$Main.
Comments (Newest First)
Ezzaral | Posting Maven | Feb 11th, 2008
•
•
•
•
Well, perhaps you could do that, but there is no reason at all that you should do that. If you want to provide method implementations along with an interface definition you should be using an abstract class.
Allen Chen | Newbie Poster | Jan 5th, 2008
•
•
•
•
Think about in any class?
manix413 | Newbie Poster | Jan 2nd, 2008
•
•
•
•
jjjjj
Post Comment
•
•
•
•
DaniWeb Marketplace (Sponsored Links)