Inheritance class Object

4

How does the compiler do to implicitly 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 must assume this pattern? Is it possible for the programmer to force the compiler to implement such behavior? Maybe even forcing the inheritance of other classes?

    
asked by anonymous 14.11.2016 / 13:31

2 answers

3
  

But how does the compiler know that all created classes should take this pattern?

This is the pattern that was created. During the development of languages, it was defined that in the hierarchical top of inheritance, there should be a super class in common.

  

Is it possible for the programmer to force the compiler to implement such behavior? Maybe even forcing the inheritance of other classes?

Not (as far as I know). It would be illogical to the contrary, because the compiler would not know how to handle the artifact. You can force the inheritance you want, but always have the first inheritance of Object .

    
14.11.2016 / 13:49
6

There is no way for the programmer to avoid the inheritance of Object in language, and as far as I know, not even on a lower level.

There's no secret to that. Every class that has no other inheritance, and places there the inheritance of Object . It does the syntactic and semantic analysis of what is written and decides what to do. The compiler knows why a programmer programmed it like this.

When there is inheritance from another class, it does not have to do this because, since all classes inherit from Object , it is true whether the inheritance of another class inherits will make this inherit from Object per hierarchy. >     

14.11.2016 / 13:46