File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes overriding methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "overriding methods" Watch "overriding methods" New topic
Author

overriding methods

Badri Sarma
Ranch Hand

Joined: Apr 01, 2003
Posts: 72
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 ]

Thanks<br />Badri
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
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 ]

SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Badri Sarma
Ranch Hand

Joined: Apr 01, 2003
Posts: 72
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

Joined: Jan 04, 2003
Posts: 867
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


Francis Siu
SCJP, MCDBA
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
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

Joined: Jan 04, 2003
Posts: 867
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

Joined: Mar 05, 2003
Posts: 1391
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

Joined: Mar 05, 2003
Posts: 1391
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

Joined: Apr 01, 2003
Posts: 72
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

Joined: Mar 05, 2003
Posts: 1391
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
 
subject: overriding methods
 
Similar Threads
abstract method overriding
abstract method implementation
calling a method in a super class from a sub class
inner class
Overriding and Exceptions