Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Test {
- // inheritance of fields
- public static void main(String[] args) {
- Sub ref=new Sub();
- ref.method();
- }
- }
- class Base
- {
- String val1="abc";
- String val2="def";
- }
- class Sub extends Base
- {
- String val2="ghi"; // do not do this!!! val2 hides super val2
- void method()
- {
- System.out.println(val1); // abc
- System.out.println(val2); // ghi
- System.out.println(super.val2); // def
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment