Pergunta de entrevista da empresa Marlabs

overload vs override

Respostas da entrevista

Sigiloso

10 de mai. de 2017

Method overriding on the other hand is declaring a method in subclass which is already present in parent class. The subclass can then provide an implementation. An example is ovveriding the toString() or equals() methods from the Object superclass and then providing specific implementation of the methods in your class. Second difference is that Overloading happens at compile-time while Overriding happens at runtime: The binding of overloaded method call to its definition has happens at compile-time however binding of overridden method call to its definition happens at runtime.

4

Sigiloso

10 de mai. de 2017

Method overloading is when you have two or more methods in a class with have the same method name but different parameters or even different return type. e.g public int sum (int a , int b){ return a + b; } public int sum (int a, int b, int c){ return sum (sum ( a, b), c); }

2