C
C#12mo ago
larva

problems with inheritance and interfaces

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