C
C#11mo ago
larva

problems with inheritance and interfaces

trying to understand the basic concepts
17 Replies
larva
larvaOP11mo ago
@alex here is good? my first question whats the difference between an interface and an abstract class other than the fact the interface makes everything abstract by default
Jimmacle
Jimmacle11mo ago
a class can implement many interfaces but can only inherit from one class abstract classes can have state, interfaces can't
larva
larvaOP11mo ago
ok jimmacle and an interface by defauly makes everything abstract right?
Jimmacle
Jimmacle11mo ago
sort of not really anymore with default interface implementations
larva
larvaOP11mo ago
No description
larva
larvaOP11mo ago
cant i use any constructor to create an object in a concrete class i dont get the static constructor part or is that part of my vision
Jimmacle
Jimmacle11mo ago
static constructors run once automatically when your class is first used
larva
larvaOP11mo ago
oh so the default constructor right?
larva
larvaOP11mo ago
No description
larva
larvaOP11mo ago
why here do i do public void method1() {} or public override void method 1() {}
Jimmacle
Jimmacle11mo ago
no, static constructor is specified static static MyClass() { } look up the warning code?
larva
larvaOP11mo ago
ok i got it basically if u implement smth from an abstract class inherit* u need to either make the method abstract again or make it concrete and override it
Jimmacle
Jimmacle11mo ago
correct
larva
larvaOP11mo ago
what if i make abstract method in class A then i make the same abstract method in Class B will i need to override it or nah public abstract void method() in class A public abstract void method() in Class B Is that correct
Jimmacle
Jimmacle11mo ago
it doesn't make sense to redefine it
larva
larvaOP11mo ago
So what will be the correct syntax If I left it as abstract In the derived class
Jimmacle
Jimmacle11mo ago
you just don't redeclare it it's already being inherited from A but if you leave it abstract you'll also have to declare class B abstract too
Want results from more Discord servers?
Add your server