Skip to content

Instantly share code, notes, and snippets.

@ChinaXing
Created August 12, 2014 05:16
Show Gist options
  • Save ChinaXing/db677d55f0ef4de6870d to your computer and use it in GitHub Desktop.
Save ChinaXing/db677d55f0ef4de6870d to your computer and use it in GitHub Desktop.
private field and function override/hidden
public class a {
private int a = 20;
private int getA(){
return a;
}
private void setA(int a){
this.a = a;
}
public void echoA(){
System.out.println(a);
System.out.println(getA());
System.out.println(this.a);
}
}
public class B extends a{
private int a = 30;
private int getA(){
return a;
}
private void setA(int a){
this.a = a;
}
public static void main(String[] args){
B b = new B();
b.echoA();
}
}
@ChinaXing
Copy link
Author

20
20
20

use javap -c B to dump the byte code view the background

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment