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 Virender,

I test this code and i get an error on this statement indeed. I see this piece of code on a java book so i’m confused. Perhaps something is missing on this statement…

i try : A a = B.super , and the compiler has accept it, i get the output : call to method f() of class B. Is this statement correct ?



Default Answered on September 24, 2014.
Add Comment

Your Answer

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