0

I am new to Java.I can't understand the meaning behind "hiding" and "overriding". Both do the same job. For example: Look the following program that I found on StackOverflow

import java.util.*;
import java.lang.*;
import java.io.*;

public class Apples {
    public static void main(String[] args) {
        Foo.method();
        Bar.method();
     }
}

class Foo {
    public static void method() {
        System.out.println("in Foo");
    }
} 

class Bar extends Foo {
    public static void method() {
        System.out.println("in Bar");
    }
}

In above program, the code

 Bar.method();

overwrites the class Foo static method. Then how it differs from overriding?

Shreyas
  • 1
  • 1
  • Method hiding is a compile-time feature. Method overriding is a run-time feature. For static methods, overriding is impossible because they're always resolved at compile-time only. – 4castle Jul 15 '17 at 07:21
  • check this [link](https://coderanch.com/wiki/659959/Overriding-Hiding) – Sahidul Hassan Razon Jul 15 '17 at 07:28

0 Answers0