6
How the compiler implicitly makes all classes inherit from object
?
This is a behavior adopted in languages such as C#, Java and others.
public class Funcionario
{
}
public class Funcionario : Object
{
}
The above example is redundant. But how does the compiler know that all created classes should take this pattern? Is it possible for the programmer to force the compiler to implement such behavior? Perhaps even forcing the inheritance of other classes?
Sorry, buddy, I didn’t see your answer before I put mine ^^.
– Gustavo Cinque
@bigwon, thank you for the answer. I believe that the syntactic and semantic analysis are the key point to my question. Is it possible to simulate such behavior via C# ? For example, I create a framework and wish all classes to inherit from object2...
– Pedro
@Pedro has no way of forcing under normal conditions. Of course he can change the compiler of the C# or make some extra tool to "guarantee it" provided you use the tool or its compiler version. But it is not recommended.
– Maniero
@Pedro in compiled languages is not possible without the compiler itself supporting this operation, which is not the case with C# or Java. But you can make some very interesting ganbiarras in some interpreted languages (e.g. Ruby)
– Genos