+ 3
What is the difference between function hiding and function overriding?
6 odpowiedzi
+ 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 😅
+ 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
+ 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).
+ 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.
+ 1
Thanks esraa
+ 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