overriding methods
posted 22 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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 ]
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
posted 22 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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 ]
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
posted 22 years ago
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
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
Thanks<br />Badri
posted 22 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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

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
posted 22 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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.
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
posted 22 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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

yes, I omit to see that part of the code because the code is too
small
thanks for your help to make it clear

Francis Siu
SCJP, MCDBA
posted 22 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
how to call a method of abstract class, i am using the concept of overriding.
In the method method() of class Test, insert super.method();Try to insert a call to super() as the first statement in the method method() declared in class Test.
Marlene Miller
Ranch Hand
Posts: 1392
posted 22 years ago
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)
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
method() in Test overrides method() in Best.There is no concept called overriding method for abstract class
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
posted 22 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hi,
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
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
Thanks<br />Badri
Marlene Miller
Ranch Hand
Posts: 1392
posted 22 years ago
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:
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Yes.I can call the method() of class Best from any other function in class Test by using super.method().
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:
| What a stench! Central nervous system shutting down. Save yourself tiny ad! The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |








