+ 4
whats the use of all of this?
Hello, I have multiple questions 1: as example class A {} class B : A {} class main { //i know to initiate a new initiate like this A hi1 = new A(); //but whats the use of doing it like this: //and why should I do it this way A hi2 = new B(); //why is the second thing B ??? } 2: whats the diverence between virtual, abstract and Interface // how I understand it they all make the same thing thank for answers
2 Respuestas
+ 1
Please take a closer look at basic concepts of object orientation. Try to understand, what exactly is inheritance. B is a child of A and therefore should not contain an attribute of A. Of course it can, but this doesn't make any sense.
0
When a class method is marked as "abstract" then this means that the function's body is mandatory to be defined in the child class. "virtual" means that you can override the function and change it's body logic in the child class, but this is not mandatory. A interface is a collection of pure abstract methods, with no implementation (no body), just their prototype (definition).