C
C#6mo ago
Gonzo

problems with inheritance and interfaces

trying to understand the basic concepts
17 Replies
Gonzo
Gonzo6mo 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
Jimmacle6mo ago
a class can implement many interfaces but can only inherit from one class abstract classes can have state, interfaces can't
Gonzo
Gonzo6mo ago
ok jimmacle and an interface by defauly makes everything abstract right?
Jimmacle
Jimmacle6mo ago
sort of not really anymore with default interface implementations
Gonzo
Gonzo6mo ago
No description
Gonzo
Gonzo6mo 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
Jimmacle6mo ago
static constructors run once automatically when your class is first used
Gonzo
Gonzo6mo ago
oh so the default constructor right?
Gonzo
Gonzo6mo ago
No description
Gonzo
Gonzo6mo ago
why here do i do public void method1() {} or public override void method 1() {}
Jimmacle
Jimmacle6mo ago
no, static constructor is specified static static MyClass() { } look up the warning code?
Gonzo
Gonzo6mo 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
Jimmacle6mo ago
correct
Gonzo
Gonzo6mo 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
Jimmacle6mo ago
it doesn't make sense to redefine it
Gonzo
Gonzo6mo ago
So what will be the correct syntax If I left it as abstract In the derived class
Jimmacle
Jimmacle6mo 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