-
interface
why we can't define the body of interface methods
-
Welcome to DevX 
That depends entirely on what you are trying to do.
I can define a simple Lion interface
Code:
public interface Lion {
boolean chaseZebra(Prey p);
void eatZebra(Prey p);
}
What are you trying to do?
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
-
Methods CAN be defined in the definition of the Interface. However, the power of using Interfaces comes from the ability to create a definition of a method which has the same signature but different implementation among other classes. The way you get this is by not defining the method in the Interface itself, but inside of the definitions of the classes which implement that Interface.
-
In its most common form, an interface is a group of related methods with empty bodies.
Implementing an interface allows a class to become more formal about the behavior it promises to provide. Interfaces form a contract between the class and the outside world, and this contract is enforced at build time by the compiler. If your class claims to implement an interface, all methods defined by that interface must appear in its source code before the class will successfully compile.
To use an interface, you write a class that implements the interface. When an insatiable class implements an interface, it provides a method body for each of the methods declared in the interface.
-
So, we ask you, why can't you define interface methods?
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
-
Do you know the reference to any standard of the Java language which says you can't define a method in an interface? I've done it, so it is either within the standard or I got away with something I shouldn't have.
My thought behind this is that there may be methods you want all members of this inheritance chain to implement, so why not define those methods in the Interface? There will be method implementations that you want to allow diversity among the children, so you just declare the method in the Interface and then define in all of the children who implement the Interface.
-
 Originally Posted by nspils
I've done it, so it is either within the standard or I got away with something I shouldn't have.
I seriously doubt if you got away with anything. Computers and computer programming languages are notoriously unforgiving when it comes to their limitations.
I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
Please use [Code]your code goes in here[/Code] tags when posting code.
Before posting your question, did you look here?
Got a question on Linux? Visit our Linux sister site.
Modifications Required For VB6 Apps To Work On Vista
Similar Threads
-
By Trey Hutcheson in forum .NET
Replies: 6
Last Post: 03-27-2002, 08:13 PM
-
By Michael Welch in forum .NET
Replies: 5
Last Post: 03-14-2002, 02:43 PM
-
By Aaron Anderson in forum .NET
Replies: 2
Last Post: 02-20-2001, 11:56 AM
-
By Vlad Ivanov in forum .NET
Replies: 0
Last Post: 12-15-2000, 02:58 PM
-
By Kevin Burton in forum .NET
Replies: 12
Last Post: 10-09-2000, 10:29 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks