RE: Keyword super in Java



I don’t undestand the following example code :

Class A
{      void f()
{   System.out.println(“call to method f() of class A”) ;

Class B extends A
{      void f()
{ System.out.println(“call to methode f()  of class B”);

public void test()
{   A a = super ;
super.f() ;

Public class Super
{   public static void main(String args[])

{ B b = new B();

Result :

call to method f() of class B // Why  a.f() display the call to f()  of class B ?
call to method f() of class A  // Ok  for me, super is a reference to an object of class A.
call to methode f() of class B // Ok, “this” is a reference to the object that call test()

Thank you.


braheim Default Asked on September 21, 2014 in Selenium WebDriver.
Add Comment
3 Answers

Hi Braheim,

I will get back to you on this today evening once I reach home.


Professor Answered on September 22, 2014.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.