File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

overriding methods

 
Badri Sarma
Ranch Hand
Posts: 72
  • 0
  • Mark post as helpful
  • send pies
  • 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 ]
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Francis Siu
Ranch Hand
Posts: 867
  • 0
  • Mark post as helpful
  • send pies
  • 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
Gold Digger
Sheriff
Posts: 7610
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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

 
Marlene Miller
Ranch Hand
Posts: 1392
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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:
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic