Posts Tagged ‘shadowing’

Hiding : Happens during inheritance (between superclass and subclass).

Shadowing : Happens within a class (between a member variable and local variable).

Examples :

Hiding :

class Parent {

String city = “Dallas”;


class Child extends Parent {

String city =”Zurich”;


“city” in Child hides the one in Parent.

Shadowing :

class Main {

String city = “Dallas”;

void method() {

String city = “Zurich”;



“city”, local variable shadows the member variable.

Read Full Post »