C# Programming - Interfaces - Discussion
Discussion Forum : Interfaces - General Questions (Q.No. 6)
6.
Which of the following statements is correct about an interface used in C#.NET?
Discussion:
10 comments Page 1 of 1.
Sanjeev said:
1 decade ago
A class cannot implement an interface partially. This should be the right answer.
Sourav said:
1 decade ago
A class cannot implement an interface partilly.
Shilpa said:
1 decade ago
A class cannot implement an interface partially. This option is correct. Because if an interface is inherited in a class all the declared method inside the class should be implemented in the derived class.
Senthil said:
1 decade ago
"If a class implements an interface partially, then it becomes an abstract class. " is the right answer but there is a change like "then it should be abstract class" because compiler gives error while implement interface partially.
Sandeep said:
1 decade ago
@Senthil:
Not it should be abstract class, it must be abstract class otherwise [B]. A class cannot implement an interface partially os the correct answer.
Not it should be abstract class, it must be abstract class otherwise [B]. A class cannot implement an interface partially os the correct answer.
Sasanka said:
1 decade ago
Example of Implementation Of Interface Partially.
public interface myinterface
{
void car();
void bike();
}
public abstract class CarRepairing : myinterface
{
public void car()
{
//do some coding
}
public abstract void bike(); //implement this method in its derived class
}
//So the answer A is correct. Check it out.
public interface myinterface
{
void car();
void bike();
}
public abstract class CarRepairing : myinterface
{
public void car()
{
//do some coding
}
public abstract void bike(); //implement this method in its derived class
}
//So the answer A is correct. Check it out.
Orknob Ghosh said:
1 decade ago
Basically in interface you can have only the method definition but no implementation whereas in case of abstract you can have both concrete methods as well as the abstract methods. So we can say if a class implements an interface partially, then it becomes an abstract class.
Priya said:
1 decade ago
A class can't implement an interface partially because suppose there are two classes (circle, square) , among them one class (circle) is implementing+declaring only one method of an interface leaving the second method only with declaration. And if I want to declare+implement of second method in another class (square) then the circle class should be made abstract and non implementing method in circle should also be made abstract and square should be derived from circle class.
Shashikant said:
9 years ago
A class can not implement an interface partially. Not even with abstract. I just checked it via a Demo.
Akash Jain said:
8 years ago
A class can implement an interface partially, because here in this question they din't mentioned that the class is not an abstract class or it can't be an abstract class and as we know that in an abstract class we can inherit interfaces and define some of the methods as well as we can retain some of the methods as abstract using 'abstract' keyword for further implementation of that method.
For an instance,
using System;
public interface ISet
{
void setId();
void setName();
}
public abstract class AbstractSet : ISet
{
public abstract void setId();
public void setName() {
}
}
public class Program : AbstractSet
{
public override void setId()
{
}
public static void Main()
{
}
}
So, option A is the right answer.
For an instance,
using System;
public interface ISet
{
void setId();
void setName();
}
public abstract class AbstractSet : ISet
{
public abstract void setId();
public void setName() {
}
}
public class Program : AbstractSet
{
public override void setId()
{
}
public static void Main()
{
}
}
So, option A is the right answer.
(1)
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers