What is the C# equivalent syntax for the following Java statement:
public class Lion extends Animal implements Diurnal() { }
The keyword extends is used when a class wants to inherit all the properties from another class or an interface that wants to inherit an interface. We use the implements keyword when we want a class to implement an interface.
Yes, you can. But you need to declare extends before implements : public class DetailActivity extends AppCompatActivity implements Interface1, Interface2 { // ... }
C++ does not provide the exact equivalent of Java interface : in C++, overriding a virtual function can only be done in a derived class of the class with the virtual function declaration, whereas in Java, the overrider for a method in an interface can be declared in a base class.
Extends : This is used to get attributes of a parent class into base class and may contain already defined methods that can be overridden in the child class. Implements : This is used to implement an interface (parent class with functions signatures only but not their definitions) by defining it in the child class.
the inheritance could be declared like this.
public class Lion : Animal, Diurnal { }
In C#
, you can inherit one base class and can be multiple Interfaces.
One more tip, if you are making an Interface
in C#, prefix it with I
. eg IDiurnal
public class Lion : Animal, // base class must go first Diurnal // then interface(s) if any { }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With