Click here to Skip to main content
12,621,228 members (34,823 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
i have an interface .details are given below

Interface myinterface
{
   void getmethods();
   void  interfacemethod();
   void methodtoimpliment();
}
 
class myclass:myinterface
{
    getmethods()
    {
        response.write("get method called");
    }
}
class Implement:myinterface
{
   interfacemethod()
    {
   response.write("interface method called:");
    }
methodtoimplement()
  {
      response.write("implement method called:");
  }
}

is it possible or not??
Posted 7-Mar-12 1:04am
Updated 7-Mar-12 1:26am
v4
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

No. You MUST implement the methods, but they don't have to do anything:

class myclass:myinterface
{
    void getmethods()
    {
        response.write("get method called");
    }
 
    void  interfacemethod() {}
 
    void methodtoimpliment() {}
        
}
  Permalink  
v2
Comments
chinta123 7-Mar-12 6:28am
   
thank you.but i have just change my question .can you please tell me is it possible or not??
nagendrathecoder 7-Mar-12 6:35am
   
Not possible.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

AFAIK it is not possible.
You have to implement all methods of interface.
Everything or Nothing.


What you are saying is not possible.
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

No, you must implement all the methods of an interface

An interface gaurantees a 'contract' - if a class implements an interface then you know that the methods on that class are available.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 4

Nope: a consumer of the interface may safely assume it may call all the methods.
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 5

no you have to split it in two interfaces.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 6

.NET does not support multiple inheritances directly because in .NET, a class cannot inherit from more than one class. .NET supports multiple inheritances through interfaces.
for more..
  Permalink  
v2
Comments
Marcus Kramer 25-Feb-13 13:59pm
   
It is not acceptable to use this site as a traffic driver for your own site. Account and posts have been flagged.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161128.1 | Last Updated 25 Feb 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100