What is the difference between function hiding and function overriding? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

What is the difference between function hiding and function overriding?

19th Aug 2019, 6:55 AM
Piyush Srivastava
Piyush Srivastava - avatar
6 Answers
+ 2
Parent class Public Class A{ Public void print() { System. Out. Println("parent class") } } Child class Public class B extends A{ Public void print() { System. Out.println("child class") } } This is function overriding The same function in the parent class (same name and( number&kind) of parameters) in child class but different implementation 🙄 I hope u understand 😅
19th Aug 2019, 6:34 PM
Esraa
Esraa - avatar
+ 2
If both method in parent class and child class are an instance method, it called overrides.[1] If both method in parent class and child class are static method, it called hiding.[1] [1]: https://stackoverflow.com/questions/10594052/overriding-vs-hiding-java-confused
19th Aug 2019, 6:58 AM
Tom Hammerbacher
Tom Hammerbacher - avatar
+ 2
In function overriding, the child class implements a function of the parent class differently. In function hiding, one class is unable to directly call the hidden/private function of another class and so has to rely on an indirect public function of the latter if it needs to access this hidden function(ality).
19th Aug 2019, 9:54 AM
Sonic
Sonic - avatar
+ 2
Sonic and tom thanks for giving me this clarity, but could u pls provide me some programs example so that i can understand it better.
19th Aug 2019, 12:40 PM
Piyush Srivastava
Piyush Srivastava - avatar
+ 1
Thanks esraa
19th Aug 2019, 8:16 PM
Piyush Srivastava
Piyush Srivastava - avatar
+ 1
1 Public calss baseClass{ Public static void primess(){ System. Out. Println("Base Class") ; } } 2 Public calss subClass extends baseClass{ Public static void primess(){ System. Out. Println("sub Class") ; } } In the main method: SubClass.primess(); The output Base Class . . Hiding method is when u create the static method in parent and child class. U know that the static (methods or values) are called by Class not object. When there's same methods in parent&child its called method hiding not overriding, u can't override statistic methods. .............. Sorry for late and prolongation
19th Aug 2019, 8:45 PM
Esraa
Esraa - avatar