• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

overriding methods

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
how to call a method of abstract class, i am using the concept of overriding.


thanks in advance
[Val added CODE tags]
[ April 09, 2003: Message edited by: Valentin Crettaz ]
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try to insert a call to super() as the first statement in the method method() declared in class Test.
Be advised that this is not going to work for the fun() method since it is abstract in class Best, and thus, it is not invokable.
[ April 09, 2003: Message edited by: Valentin Crettaz ]
 
Badri Sarma
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Valentin Crettaz:
Try to insert a call to super() as the first statement in the method method() declared in class Test.
[ April 09, 2003: Message edited by: Valentin Crettaz ]


Is this the only way to access the method of base class.
If so then "class Test" is not overriding the method().
There is no concept called overriding method for abstract class
Is that so, correct me please if i am wrong
 
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,Badrinath
how to call a method of abstract class?
in your code
you can use
Best.method();
to call the method of super class
 
Valentin Crettaz
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Siu,
method() is not a static method, and thus, you need a reference upon which to invoke it. The statement Best.method() will not compile.
 
Francis Siu
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Valentin
yes, I omit to see that part of the code because the code is too small
thanks for your help to make it clear

 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

how to call a method of abstract class, i am using the concept of overriding.

Try to insert a call to super() as the first statement in the method method() declared in class Test.

In the method method() of class Test, insert super.method();
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

There is no concept called overriding method for abstract class

method() in Test overrides method() in Best.
A method in a subclass overrides an abstract method in a superclass or superinterface if they have the same the signature and the method in the superclass is not private and is accessible from the subclass. (See JLS 8.4.6.1)
 
Badri Sarma
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Originally posted by Marlene Miller:
In the method method() of class Test, insert super.method();



if i write super.method() in the method() of class Test, then i am calling both the methods of class Best and Test for which overridding is not necessary and more over it is not the "OO" concept of overriding. I can call the method() of class Best from any other function in class Test by using super.method().
So, overriding concept still exist in abstract classes.
thanks
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I can call the method() of class Best from any other function in class Test by using super.method().

Yes.
super.method() is the *only* way to access an overridden method from code in the subclass.
Compare casting �this� for fields and methods:

Another interesting test:
 
reply
    Bookmark Topic Watch Topic
  • New Topic