namespace FinalExam
{
class Developer
{
string name;
public void sayGoodMorning()
{
Console.Write("Good Morning! ");
}
public void sayHi()
{
Console.WriteLine("Hi!");
}
public void startDiscussion()
{
Console.WriteLine("How is going your work?");
}
public void setName(string a)
{
name = a;
}
public void getName()
{
Console.WriteLine(name);
}
}
class BackEnd : Developer
{
}
class FrontEnd : Developer
{
}
class FrontEndBackEndTest
{
static void Main(string[] args)
{
Developer Zaur = new Developer();
Zaur.sayGoodMorning();
Console.WriteLine();
BackEnd backEnd = new BackEnd();
backEnd.setName("Ben");
backEnd.sayGoodMorning();
backEnd.getName();
Console.WriteLine();
FrontEnd frontEnd = new FrontEnd();
frontEnd.setName("Jane");
frontEnd.sayHi();
frontEnd.startDiscussion();
}
}
}
my class was like this(don't mind names or calling objects just for example) in this example must be write something in child class or can be empty?
CodePudding user response:
Yes, a class which extends another class can be empty.
You're code compiles and runs, and therefore is allowed by the c# compiler.
However, it seems pointless to have an empty class (in practice, I do understand that this is only an example) when you could just make the backEnd
an instance of Developer
itself unless at some point you need to differentiate between them via types (ie. backEnd.GetType()
).