9 Replies Latest reply: Mar 16, 2009 6:51 AM by 807588 RSS

    Using the word super to access superclass fields - How?

    807588
      I just read that it is possible to access public members of the superclass by using the keyword super. To test it, I tried the following but it does not work. What is the proper way?
      public class A {
      
           public String color = "Black";     
           
      }
      
      public class B extends A{
      
           public String color = "White";
      }
      
      public class test {
           public static void main(String[] args) {
                
                A x= new A();
                B y= new B();
                
                System.out.println(x.color); //returns Black
                
                System.out.println(y.color); //returns White
                System.out.println(y.super.color); ERROR!!!
           }
      }