Exp like :- class Program : IA, IB, XYZ
Error - Base class 'XYZ' must come before any interfaces
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ImplementMultipleInheritanceWithClass
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ImplementMultipleInheritanceWithClass
{
public interface IA
{
void show();
}
public interface IB
{
void show();
}
public class XYZ
{
public void Display()
{
Console.WriteLine("Display method");
}
}
class Program : IA, IB, XYZ //Error - Base class 'XYZ' must come before any interfaces
{
static void Main(string[] args)
{
IA ai = new Program();
ai.show();
IB bi = new Program();
bi.show();
Console.ReadLine();
}
void IA.show()
{
Console.WriteLine("IA interface method show.");
}
void IB.show()
{
Console.WriteLine("IB interface method show.");
}
}
}
}
Error - Base class 'XYZ' must come before any interfaces
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ImplementMultipleInheritanceWithClass
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ImplementMultipleInheritanceWithClass
{
public interface IA
{
void show();
}
public interface IB
{
void show();
}
public class XYZ
{
public void Display()
{
Console.WriteLine("Display method");
}
}
class Program : IA, IB, XYZ //Error - Base class 'XYZ' must come before any interfaces
{
static void Main(string[] args)
{
IA ai = new Program();
ai.show();
IB bi = new Program();
bi.show();
Console.ReadLine();
}
void IA.show()
{
Console.WriteLine("IA interface method show.");
}
void IB.show()
{
Console.WriteLine("IB interface method show.");
}
}
}
}
So, how to resolve this error-
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ImplementMultipleInheritanceWithClass
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ImplementMultipleInheritanceWithClass
{
public interface IA
{
void show();
}
public interface IB
{
void show();
}
public class XYZ
{
public void Display()
{
Console.WriteLine("Display method");
}
}
class Program : XYZ, IA, IB // corrected at this point
{
static void Main(string[] args)
{
IA ai = new Program();
ai.show();
IB bi = new Program();
bi.show();
Console.ReadLine();
}
void IA.show()
{
Console.WriteLine("IA interface method show.");
}
void IB.show()
{
Console.WriteLine("IB interface method show.");
}
}
}
}
output:-
IA interface method show.
IB interface method show.
No comments:
Post a Comment