Variable shadowing has to do with your understanding for scoping. If a class
declares a member variable, then it can be over-shadowed by a local variable
declared in a method with the same name.
See code sample below:
class
Test {
static public void main(
String[] arg) {
Foo a = new Foo();
System.out.println(a.i);
a.FromFn();
}
}
class Foo {
public int i=12;
void FromFn() {
int i=99;
System.out.println(i); // local (over-shadowed i)
System.out.println(this.i); // class i
}
}
Method overriding had to do with subclassing, if class B extends class A, a
method is said to be overridded if the method from class A is redeclared in
Class B having the same name, argument list and return type.
In the code sample below class B overrides the SayHi() method from class A
class Test {
static public void main(String[] arg) {
A a = new A();
B b = new B();
a.SayHi();
b.SayHi();
}
}
class A {
void SayHi() {
System.out.println("Hi from class A");
}
}
class B extends A {
void SayHi() {
System.out.println("Hi from class B");
}
}